1

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
Febrium
  • 55
  • 1
  • 2
  • 5
  • 2
    I have done similar things without the effects you describe. I would guess the problem is elsewhere. – Lennart Regebro May 03 '13 at 05:51
  • 1
    Why is `AdminEdit` inheriting from `Edit` and not `UpdateView`? – danodonovan May 03 '13 at 10:30
  • The inheritance chain is `AdminEdit -> Edit -> UpdateView`. But it stops at `Edit` since `Edit` fulfills each of AdminEdits requirements. It's related to the MRO of Python and newstyle classes. This could perhaps help you more -> http://stackoverflow.com/questions/1848474/method-resolution-order-mro-in-new-style-python-classes – Henrik Andersson May 03 '13 at 11:21

0 Answers0