Introduction Let's talk about models a common design features
two properties and methods of
a choice attribute
grammar choice = ((key: text) , (key: text)) #
method get_column.display ()
EG xingbie = forms.ChoiceField (choice = ( (1 "male), (2," female ")), default = 1) -> forms must specify the type of hard-coded
eg sex = models.CharField (verbose_name = 'sex', max_length = 5, choices = ( ( 'male', 'male'), ( 'female', ' female')), default = 'male ') -> models do not have
two value method
froms.get_xingbie.display () # print that text value
froms. xingbie # print is key
three methods inherited models, along with changes in the database changes (recommended in this way)
publish = forms.ModelChoiceField (QuerySet = models.objects.all ()) # required forms using ModelChoiceField
display user.object method solution, add models in
DEF __str __ (Self):
return Self.get_jifang_display ()
to be solved here is a problem, displays N number of duplicate records