I\'m trying to update certain fields a ModelForm, these fields are not fixed. (I have only tutor
that is autopopulated by the view)
Model:
You can invoke form's constructor like this:
class SessionForm(forms.ModelForm):
class Meta:
model = Session
exclude = ['tutor', 'start_time']
def __init__(self, your_extra_args, *args, **kwargs):
super(SessionForm, self).__init__(*args, **kwargs)
if need_end_time_start_time(your_extra_args):
self.fields['start_time'] = forms.DateTimeField()
To use this class, you have to pass an argument "your_extra_args" to your form:
session_form = SessionForm('foo')