外观
ModelForm的字段选择
在选择字段时使用ModelForm的fields属性,在复制列表内将想要的字段都添加进去,或者使用__all__添加所有字段或使用exclude排除字段。如:
from django.forms import ModelForm
# __all__表示将所有字段都添加到表单中
class AuthorForm(ModelForm):
class Meta:
model = Author
fields = '__all__'
# exclude表示将模型类除排除外的字段都添加进来
class AuthorForm(ModelForm):
class Meta:
model = Author
excludes = ['title']