本文整理汇总了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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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]
示例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
示例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
示例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