How can I pass an initial value for a field to a model form. I have something like the following code
class ScreeningForm(forms.ModelForm):
class Meta:
model = Screening
def __init__(self, *args, **kwargs):
super(ScreeningForm, self).__init__(*args, **kwargs)
self.fields['blood_screen_type'] = CommaSeparatedCharField(
label=self.fields['blood_screen_type'].label,
initial=self.fields['blood_screen_type'].initial,
required=False,
widget=CommaSeparatedSelectMultiple(choices=BLOOD_SCREEN_TYPE_CHOICES)
)
class ScreeningAdmin(admin.ModelAdmin):
#form = ScreeningForm
form = ScreeningForm(initial={'log_user':get_current_user()})
Now I want to pass an initial value for a field of the Person class. How can I do that?
form =
portion must be form Class and not an form object.