Opened 7 years ago
Last modified 7 years ago
#28326 closed New feature
[new feature] — at Version 1
Reported by: | Luoxzhg | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.11 |
Severity: | Normal | Keywords: | ModelForm, Meta, initials, modelform_factory |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Now, we can specify 'widgets', 'labels', and so on in ModelForm's Meta innerclass and modelform_factory. But We can't specify 'initials' in Meta and modelform_factory. We must provide initial values in explicitly defined fields or in ModelForm instantiation.
class Person(models.Model): first = models.CharField(max_length=10) last = models.CharField(max_length=10) class PersonForm(forms.ModelForm): last = forms.CharField(max_length=10, required=True, initial="Smith") class Meta: model = Person fields = '__all__'
If we can specify initial values in Meta, it is easier to specify initial values:
class PersonForm(forms.ModelForm): class Meta: model = Person fields = '__all__' initials = {'last': 'Smith'}
Note:
See TracTickets
for help on using tickets.