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 shoul
For what it's worth, the FormView class-based view way to do this would be to override the FormView's get_initial function. get_initial returns the initial keyword arguments used by get_form_kwargs to instantiate the form.
Docs:
get_initial, here,get_form_kwargs, here.Sample code:
from django.views.generic.edit import FormView
class MyFormView(FormView):
def get_initial(self):
initial = super(MyFormView, self).get_initial()
# update initial field defaults with custom set default values:
initial.update({'charfield1': 'foo', 'charfield2': 'bar'})
return initial