In a custom ModelForm, I would like to have a HiddenInput field which has the value of the Autofield primary key of the model. If the form is created without a model, then this field would be None. If a model is provided to instantiate the form, it should contain the Autofield ID of the model. Is this possible? I am thinking something like this:
class MyCustomForm(forms.ModelForm):
the_id = forms.HiddenInput()
def __init__(self, *args, **kwargs):
super(MyCustomForm, self).__init__(*args, **kwargs)
self.fields["the_id"].initial = args.get('id', None)