I'm trying to prepopulate the data in my django form based on some information, but NOT using ModelForm, so I can't just set the instance.
This seems like it should be really easy, but for some reason I can't find any documentation telling me how to do this. This is my form:
class MyForm(forms.Form):
charfield1 = forms.CharField(max_length=3)
charfield2 = forms.CharField(max_length=3)
choicefield = forms.ModelChoiceField(MyModel.objects.all())
I tried just doing:
form = MyForm()
form.charfield1 = "foo"
form.charfield2 = "bar"
# a model choice field
form.choicefield = MyModel.objects.get(id=3)
which does not work.