Allow providing initial data in ModelForm Meta
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'}
Change History
(3)
Description: |
modified (diff)
|
Resolution: |
→ wontfix
|
Status: |
new → closed
|
Summary: |
[new feature] → Allow providing intial data in ModelForm Meta
|
Summary: |
Allow providing intial data in ModelForm Meta → Allow providing initial data in ModelForm Meta
|
We aren't going to add more and more override options in
Meta
. The decision from #20000: "It's understood that we have to draw a line somewhere, else we would have field definitions in theMeta
, but I believe that line should be drawn at "anything cosmetic" available throughMeta
overrides, and "anything functional" through fields overrides."