Django 的 ModelForm - Meta 选项列表在哪里? [英] Django's ModelForm - where is the list of Meta options?
本文介绍了Django 的 ModelForm - Meta 选项列表在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
In the Django documentation, where is the definitive list of Meta
options for django.forms.models.ModelForm
? (e.g., model
, exclude
, fields
, widgets
) I'm looking for the equivalent of Model Meta Options.
解决方案
Had this question myself today. For completeness, here is the documentation that currently exists:
https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#modelforms-overriding-default-fields
And an excerpt from django/forms/models.py:
class ModelFormOptions:
def __init__(self, options=None):
self.model = getattr(options, 'model', None)
self.fields = getattr(options, 'fields', None)
self.exclude = getattr(options, 'exclude', None)
self.widgets = getattr(options, 'widgets', None)
self.localized_fields = getattr(options, 'localized_fields', None)
self.labels = getattr(options, 'labels', None)
self.help_texts = getattr(options, 'help_texts', None)
self.error_messages = getattr(options, 'error_messages', None)
self.field_classes = getattr(options, 'field_classes', None)
From that list, I searched for each option on the docs page to find what I needed. Hope that helps someone.
这篇关于Django 的 ModelForm - Meta 选项列表在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文