當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.DeclarativeFieldsMetaclass方法代碼示例

本文整理匯總了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) 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:10,代碼來源:dashboard.py

示例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 
開發者ID:erdem,項目名稱:django-admino,代碼行數:33,代碼來源:serializers.py


注:本文中的django.forms.forms.DeclarativeFieldsMetaclass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。