A syntax
froms.py
class ModelForm (forms.ModelForm):
class Meta -:
Model # = modelsname specified model
fields = 1 "__all__" all specified field value #
2 include = [column1, column2] # specified field
3 exclude = [column1, colum2] # troubleshooting certain fields
labels = { 'key': ' test'} # specifying field described
err_messages = {title: { 'required ', ' not empty'}}
DEF the __init __ (Self, args *, ** kwargs ): batch # format
Super () .__ the init __ (* args, ** kwargs)
for Filed in self.fields.values ():
filed.error_messages = { 'required': "this field can not be blank"}
Filed. widget.attrs.update ({ 'class': ' form-control'})
views.py
= ModelForm form (request.POST)
form.save () # database stores
two points Update
1 ModelForm (instance = object) #object editable object model query,
form = ModelForm (= Object instance)
the render} {form
III summarizes the
1 ModelForm will be included in the Form of all things, but also expanded the number of other features, it is recommended to use