I'm sending an optional value through a url to a generic view which uses a Modelform like so:
class myClass(generic.CreateView):
template_name = 'template.html'
form_class = myForm
...
The modelform is something like:
class myForm(ModelForm):
institution = CustomModelChoiceField(...)
class Meta:
model = myModel
...
I need to set the default selected value in the dropdown field to the value passed in the url.
The value being passed is the 'id' of the model.
- How would I pass the value to myForm?
- How would myForm set it as the 'selected' value?
I'm open to other ways to doing this.
The bigger picture:
I have a form1(model 1) where I popup another form2(model2)(foreign key to model 1). On success of form2, form1 dropdown sets to the new foreigh key.
I've thought about doing it through AJAX, but for future features, it would be a good idea to pass the value in the url.
Again, open to other ways.
Thanks.