1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

[1.7.x] Fixed #22510 -- Harden field removal to only None.

Refs #8620.

If we allow any value to remove form fields then we get name clashes
with method names, media classes etc. There was a backwards
incompatibility introduced meaning ModelForm subclasses with declared
fields called media or clean would lose those fields.

Field removal is now only permitted by using the sentinel value None.
The docs have been slightly reworded to refer to removal of fields
rather than shadowing.

Thanks to gcbirzan for the report and initial patch, and several of the
core team for opinions.

Backport of 9fb0f5dddc from master
This commit is contained in:
Marc Tamlyn
2014-05-24 10:52:18 +01:00
parent cdfefbec72
commit be733bf672
5 changed files with 39 additions and 13 deletions

View File

@@ -544,8 +544,8 @@ Forms
inheriting from both ``Form`` and ``ModelForm`` simultaneously have been
removed as long as ``ModelForm`` appears first in the MRO.
* It's now possible to opt-out from a ``Form`` field declared in a parent class
by shadowing it with a non-``Field`` value.
* It's now possible to remove a field from a ``Form`` when subclassing by
setting the name to ``None``.
* The new :meth:`~django.forms.Form.add_error()` method allows adding errors
to specific form fields.