本文整理汇总了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