Opened 10 years ago
Closed 10 years ago
#23824 closed Uncategorized (duplicate)
excluded fields on ModelForm does not work on inherited fields
Reported by: | Ben Davis | Owned by: | |
---|---|---|---|
Component: | Forms | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (5)
comment:1 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 10 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:3 by , 10 years ago
This would be the test to reproduce the issue:
-
tests/model_forms/tests.py
a b class ModelFormBaseTest(TestCase): 473 473 def test_subclassmeta_form(self): 474 474 class SomeCategoryForm(forms.ModelForm): 475 475 checkbox = forms.BooleanField() 476 othertext = forms.CharField() 476 477 477 478 class Meta: 478 479 model = Category … … class ModelFormBaseTest(TestCase): 483 484 list. 484 485 """ 485 486 class Meta(SomeCategoryForm.Meta): 486 exclude = ['url' ]487 exclude = ['url', 'othertext'] 487 488 488 489 self.assertHTMLEqual( 489 490 str(SubclassMeta()),
comment:4 by , 10 years ago
I think the documentation was added in #8620, but perhaps it needs further clarification?
comment:5 by , 10 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
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).
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:
Then you can see a number field in the form, but it doesn't get saved. Should I document it somewhere?