1👍
✅
If I understand correctly, you can override a get_form_kwargs
method to pass id
into the form constructor (see this)
# views.py
def get_form_kwargs(self):
kwargs = super(CreateView, self).get_form_kwargs()
kwargs.update({'id': self.kwargs.get('id')})
return kwargs
# forms.py
def __init__(self, *args, **kwargs):
id = kwargs.pop('id', None)
super(Form, self).__init__(*args, **kwargs)
self.fields['id'].initial = id
Source:stackexchange.com