本文整理匯總了Python中django.forms.forms.DeclarativeFieldsMetaclass方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.DeclarativeFieldsMetaclass方法的具體用法?Python forms.DeclarativeFieldsMetaclass怎麽用?Python forms.DeclarativeFieldsMetaclass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.forms.forms
的用法示例。
在下文中一共展示了forms.DeclarativeFieldsMetaclass方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_widget_params_form
# 需要導入模塊: from django.forms import forms [as 別名]
# 或者: from django.forms.forms import DeclarativeFieldsMetaclass [as 別名]
def get_widget_params_form(self, wizard):
data = wizard.get_cleaned_data_for_step(wizard.steps.first)
widget_type = data['widget_type']
widget = widget_manager.get(widget_type)
fields = copy.deepcopy(widget.base_fields)
if 'id' in fields:
del fields['id']
return DeclarativeFieldsMetaclass("WidgetParamsForm", (forms.Form,), fields)
示例2: obj_as_dict
# 需要導入模塊: from django.forms import forms [as 別名]
# 或者: from django.forms.forms import DeclarativeFieldsMetaclass [as 別名]
def obj_as_dict(o):
if isinstance(o, DeclarativeFieldsMetaclass):
o = FormSerializer(form=o).data
if isinstance(o, forms.Field):
o = FormFieldSerializer(field=o).data
if isinstance(o, forms.Widget):
o = FormWidgetSerializer(widget=o).data
if isinstance(o, (list, tuple)):
o = [obj_as_dict(x) for x in o]
if isinstance(o, Promise):
try:
o = force_unicode(o)
except:
# Item could be a lazy tuple or list
try:
o = [obj_as_dict(x) for x in o]
except:
raise Exception('Unable to resolve lazy object %s' % o)
if callable(o):
o = o()
if isinstance(o, dict):
for k, v in o.items():
o[k] = obj_as_dict(v)
return o