当前位置: 首页>>代码示例>>Python>>正文


Python models.fields_for_model方法代码示例

本文整理汇总了Python中django.forms.models.fields_for_model方法的典型用法代码示例。如果您正苦于以下问题:Python models.fields_for_model方法的具体用法?Python models.fields_for_model怎么用?Python models.fields_for_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms.models的用法示例。


在下文中一共展示了models.fields_for_model方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_modelinstance_form

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def get_modelinstance_form(metadata_class):
    model_class = metadata_class._meta.get_model('modelinstance')

    # Restrict content type choices to the models set in seo_models
    content_types = get_seo_content_types(metadata_class._meta.seo_models)

    # Get a list of fields, with _content_type at the start
    important_fields = ['_content_type'] + ['_object_id'] + core_choice_fields(metadata_class)
    _fields = important_fields + list(fields_for_model(model_class,
                                                  exclude=important_fields).keys())

    class ModelMetadataForm(forms.ModelForm):
        _content_type = forms.ModelChoiceField(
            queryset=ContentType.objects.filter(id__in=content_types),
            empty_label=None,
            label=capfirst(_("model")),
        )

        _object_id = forms.IntegerField(label=capfirst(_("ID")))

        class Meta:
            model = model_class
            fields = _fields

    return ModelMetadataForm 
开发者ID:whyflyru,项目名称:django-seo,代码行数:27,代码来源:admin.py

示例2: get_view_form

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def get_view_form(metadata_class):
    model_class = metadata_class._meta.get_model('view')

    # Restrict content type choices to the models set in seo_models
    view_choices = [(key, " ".join(key.split("_"))) for key in get_seo_views(metadata_class)]
    view_choices.insert(0, ("", "---------"))

    # Get a list of fields, with _view at the start
    important_fields = ['_view'] + core_choice_fields(metadata_class)
    _fields = important_fields + list(fields_for_model(model_class,
                                                  exclude=important_fields).keys())

    class ModelMetadataForm(forms.ModelForm):
        _view = forms.ChoiceField(label=capfirst(_("view")),
                                  choices=view_choices, required=False)

        class Meta:
            model = model_class
            fields = _fields

    return ModelMetadataForm 
开发者ID:whyflyru,项目名称:django-seo,代码行数:23,代码来源:admin.py

示例3: extract_panel_definitions_from_model_class

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def extract_panel_definitions_from_model_class(model, exclude=None):
    if hasattr(model, 'panels'):
        return model.panels

    panels = []

    _exclude = []
    if exclude:
        _exclude.extend(exclude)

    fields = fields_for_model(model, exclude=_exclude, formfield_callback=formfield_for_dbfield)

    for field_name, field in fields.items():
        try:
            panel_class = field.widget.get_panel()
        except AttributeError:
            panel_class = FieldPanel

        panel = panel_class(field_name)
        panels.append(panel)

    return panels 
开发者ID:wagtail,项目名称:wagtail,代码行数:24,代码来源:edit_handlers.py

示例4: get_view_form

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def get_view_form(metadata_class):
    model_class = metadata_class._meta.get_model('view')

    # Restrict content type choices to the models set in seo_models
    view_choices = [(key, " ".join(key.split("_"))) for key in
                    get_seo_views(metadata_class)]
    view_choices.insert(0, ("", "---------"))

    # Get a list of fields, with _view at the start
    important_fields = ['_view'] + core_choice_fields(metadata_class)

    _fields = important_fields + list(fields_for_model(model_class,
                                      exclude=important_fields).keys())

    class ModelMetadataForm(forms.ModelForm):
        _view = forms.ChoiceField(label=capfirst(_("view")),
                                  choices=view_choices, required=False)

        class Meta:
            model = model_class
            fields = _fields

    return ModelMetadataForm 
开发者ID:romansalin,项目名称:django-seo2,代码行数:25,代码来源:admin.py

示例5: get_model_form

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def get_model_form(metadata_class):
    model_class = metadata_class._meta.get_model('model')

    # Restrict content type choices to the models set in seo_models
    content_types = get_seo_content_types(metadata_class._meta.seo_models)
    content_type_choices = [(x._get_pk_val(), smart_str(x)) for x in
                            ContentType.objects.filter(id__in=content_types)]

    # Get a list of fields, with _content_type at the start
    important_fields = ['_content_type'] + core_choice_fields(metadata_class)
    _fields = important_fields + list(fields_for_model(model_class,
                                                  exclude=important_fields).keys())

    class ModelMetadataForm(forms.ModelForm):
        _content_type = forms.ChoiceField(label=capfirst(_("model")),
                                          choices=content_type_choices)

        class Meta:
            model = model_class
            fields = _fields

        def clean__content_type(self):
            value = self.cleaned_data['_content_type']
            try:
                return ContentType.objects.get(pk=int(value))
            except (ContentType.DoesNotExist, ValueError):
                raise forms.ValidationError("Invalid ContentType")

    return ModelMetadataForm 
开发者ID:whyflyru,项目名称:django-seo,代码行数:31,代码来源:admin.py

示例6: get_path_form

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def get_path_form(metadata_class):
    model_class = metadata_class._meta.get_model('path')

    # Get a list of fields, with _view at the start
    important_fields = ['_path'] + core_choice_fields(metadata_class)
    _fields = important_fields + list(fields_for_model(model_class,
                                                  exclude=important_fields).keys())

    class ModelMetadataForm(forms.ModelForm):
        class Meta:
            model = model_class
            fields = _fields

    return ModelMetadataForm 
开发者ID:whyflyru,项目名称:django-seo,代码行数:16,代码来源:admin.py

示例7: fields

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def fields(cls):
        widget_fields = [
            f.name for f in Widget._meta.fields]

        return fields_for_model(
            cls, exclude=widget_fields,
            widgets=WIDGETS) 
开发者ID:django-leonardo,项目名称:django-leonardo,代码行数:9,代码来源:widget.py

示例8: set_value_field

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def set_value_field(self, model, field_name):
        """
        Adds a ``value`` field to this form that uses the appropriate formfield for the named target
        field.  This will help to ensure that the value is correctly validated.
        """
        fields = fields_for_model(model, fields=[field_name])
        self.fields['value'] = fields[field_name] 
开发者ID:salopensource,项目名称:sal,代码行数:9,代码来源:forms.py

示例9: get_model_form

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def get_model_form(metadata_class):
    model_class = metadata_class._meta.get_model('model')

    # Restrict content type choices to the models set in seo_models
    content_types = get_seo_content_types(metadata_class._meta.seo_models)
    content_type_choices = [(x._get_pk_val(), smart_text(x)) for x in
                            ContentType.objects.filter(id__in=content_types)]

    # Get a list of fields, with _content_type at the start
    important_fields = ['_content_type'] + core_choice_fields(metadata_class)
    _fields = important_fields + list(fields_for_model(model_class,
                                      exclude=important_fields).keys())

    class ModelMetadataForm(forms.ModelForm):
        _content_type = forms.ChoiceField(label=capfirst(_("model")),
                                          choices=content_type_choices)

        class Meta:
            model = model_class
            fields = _fields

        def clean__content_type(self):
            value = self.cleaned_data['_content_type']
            try:
                return ContentType.objects.get(pk=int(value))
            except (ContentType.DoesNotExist, ValueError):
                raise forms.ValidationError("Invalid ContentType")

    return ModelMetadataForm 
开发者ID:romansalin,项目名称:django-seo2,代码行数:31,代码来源:admin.py

示例10: get_modelinstance_form

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def get_modelinstance_form(metadata_class):
    model_class = metadata_class._meta.get_model('modelinstance')

    # Restrict content type choices to the models set in seo_models
    content_types = get_seo_content_types(metadata_class._meta.seo_models)

    # Get a list of fields, with _content_type at the start
    important_fields = ['_content_type'] + ['_object_id'] + core_choice_fields(
        metadata_class)
    _fields = important_fields + list(fields_for_model(model_class,
                                      exclude=important_fields).keys())

    class ModelMetadataForm(forms.ModelForm):
        _content_type = forms.ModelChoiceField(
            queryset=ContentType.objects.filter(id__in=content_types),
            empty_label=None,
            label=capfirst(_("model")),
        )

        _object_id = forms.IntegerField(label=capfirst(_("ID")))

        class Meta:
            model = model_class
            fields = _fields

    return ModelMetadataForm 
开发者ID:romansalin,项目名称:django-seo2,代码行数:28,代码来源:admin.py

示例11: get_path_form

# 需要导入模块: from django.forms import models [as 别名]
# 或者: from django.forms.models import fields_for_model [as 别名]
def get_path_form(metadata_class):
    model_class = metadata_class._meta.get_model('path')

    # Get a list of fields, with _view at the start
    important_fields = ['_path'] + core_choice_fields(metadata_class)
    _fields = important_fields + list(fields_for_model(model_class,
                                      exclude=important_fields).keys())

    class ModelMetadataForm(forms.ModelForm):
        class Meta:
            model = model_class
            fields = _fields

    return ModelMetadataForm 
开发者ID:romansalin,项目名称:django-seo2,代码行数:16,代码来源:admin.py


注:本文中的django.forms.models.fields_for_model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。