Since your ModelForm is associated with a Person-Model, you can either pass a Person-Instance:
form = PersonForm(instance=Person.objects.get(foo=bar)
or overwrite the init method of ModelForm:
class PersonForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(PersonForm, self).__init__(*args, **kwargs) self.fields['foo'].value = 'bar' class Meta: model = Person exclude = ['name']
This is not verified. I'm not sure if the βvalueβ is right, I don't have Django-Installation here, but basically this is how it works.
source share