看了源代码和官方文档,但还是不明白fields到底改变了什么?
django/forms/models.py:
'fields' is an optional list of field names. If provided, only the named
fields will be included in the returned dict.
class MyForm(forms.ModelForm):
realname = forms.CharField()
phone = forms.CharField()
class Meta:
model = MyUser
fields = ('phone',)
form = MyForm()
# 照样会输出realname
form.as_table()