[Django] #23824: excluded fields on ModelForm does not work on inherited fields

3 views
Skip to first unread message

Django

unread,
Nov 14, 2014, 3:22:34 PM11/14/14
to django-...@googlegroups.com
#23824: excluded fields on ModelForm does not work on inherited fields
-------------------------------+--------------------
Reporter: bendavis78 | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
When you have a `ModelForm` subclass, any fields in the `exclude` array
are still included on the form if the field is part of the parent class.
This happens in `ModelFormMetaClass.__new__` when the class overrides
`new_class.base_fields` with the parent fields *after* applying the
exclusions.

--
Ticket URL: <https://code.djangoproject.com/ticket/23824>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 15, 2014, 5:24:10 AM11/15/14
to django-...@googlegroups.com
#23824: excluded fields on ModelForm does not work on inherited fields
-------------------------------+---------------------------------------
Reporter: bendavis78 | Owner: olasitarska
Type: Uncategorized | Status: assigned
Component: Forms | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by olasitarska):

* status: new => assigned
* needs_better_patch: => 0
* owner: nobody => olasitarska
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/23824#comment:1>

Django

unread,
Nov 15, 2014, 5:41:07 AM11/15/14
to django-...@googlegroups.com
#23824: excluded fields on ModelForm does not work on inherited fields
-------------------------------+--------------------------------------
Reporter: bendavis78 | Owner:

Type: Uncategorized | Status: new
Component: Forms | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by olasitarska):

* status: assigned => new
* owner: olasitarska =>


Comment:

Together with Baptiste and Loic I managed to reproduce that, but we've
decided that this is an expected behaviour. It only happens when you
actually declare a field in a model form:

{{{
#!python
from django import forms

from .models import SampleModel

class BaseForm(forms.ModelForm):
number = forms.CharField()

class Meta:
model = SampleModel

class SubclassForm(BaseForm):

class Meta(BaseForm.Meta):
exclude = ['number',]
}}}

Then you can see a number field in the form, but it doesn't get saved.
Should I document it somewhere?

--
Ticket URL: <https://code.djangoproject.com/ticket/23824#comment:2>

Django

unread,
Nov 15, 2014, 5:42:28 AM11/15/14
to django-...@googlegroups.com
#23824: excluded fields on ModelForm does not work on inherited fields
-------------------------------+--------------------------------------
Reporter: bendavis78 | Owner:

Type: Uncategorized | Status: new
Component: Forms | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by dbrgn):

This would be the test to reproduce the issue:

{{{
#!diff
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -473,6 +473,7 @@ class ModelFormBaseTest(TestCase):
def test_subclassmeta_form(self):
class SomeCategoryForm(forms.ModelForm):
checkbox = forms.BooleanField()
+ othertext = forms.CharField()

class Meta:
model = Category
@@ -483,7 +484,7 @@ class ModelFormBaseTest(TestCase):
list.
"""
class Meta(SomeCategoryForm.Meta):
- exclude = ['url']
+ exclude = ['url', 'othertext']

self.assertHTMLEqual(
str(SubclassMeta()),
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23824#comment:3>

Django

unread,
Nov 15, 2014, 5:47:25 AM11/15/14
to django-...@googlegroups.com
#23824: excluded fields on ModelForm does not work on inherited fields
-------------------------------+--------------------------------------
Reporter: bendavis78 | Owner:

Type: Uncategorized | Status: new
Component: Forms | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by timgraham):

I think the documentation was added in #8620, but perhaps it needs further
clarification?

--
Ticket URL: <https://code.djangoproject.com/ticket/23824#comment:4>

Django

unread,
Nov 17, 2014, 1:15:49 PM11/17/14
to django-...@googlegroups.com
#23824: excluded fields on ModelForm does not work on inherited fields
-------------------------------+--------------------------------------
Reporter: bendavis78 | Owner:
Type: Uncategorized | Status: closed
Component: Forms | Version: 1.7
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => duplicate


Comment:

Closing as duplicate unless reporter can provide additional information as
to why the current documentation is insufficient (I'd guess he probably
didn't see it).

--
Ticket URL: <https://code.djangoproject.com/ticket/23824#comment:5>

Reply all
Reply to author
Forward
0 new messages