I have two form classes, each of which are a ModelForm of the same model. One is called ProjectForm
and the other is called AdminProjectForm
. ProjectForm
has a number of fields excluded, AdminProjectForm
does not.
In my views, I'm using two classes, Edit
and AdminEdit
. Edit
uses the Django generic editing view of UpdateView
and has the form_class
set to ProjectForm
. AdminEdit
is a inherits Edit
and has the form_class
set to AdminProjectEdit
.
One would think this would mean that the form generated by AdminEdit
would thus show the fields that are excluded on Edit
. This part is working correctly - the form fields are drawn perfectly fine (and not drawn on Edit
. However, when submitting the AdminEdit
form, any field excluded in ProjectForm
is stripped and not saved. Any suggestions?
Here's my forms.py
:
class ProjectForm(ModelForm):
class Meta:
model = Project
exclude = ('field1', 'field2', 'field3', 'qualifies_for_judging', 'reason_for_disqualification', 'finalist', 'hashtag')
class AdminProjectForm(ModelForm):
class Meta:
model = Project
exclude = ()
And my views.py:
class Edit(UpdateView):
model = Project
form_class = ProjectForm
class AdminEdit(Edit):
model = Project
form_class = AdminProjectForm