diff options
| author | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-05-24 10:52:18 +0100 |
|---|---|---|
| committer | Marc Tamlyn <marc.tamlyn@gmail.com> | 2014-05-24 13:11:50 +0100 |
| commit | be733bf672eebb7d03061a293a2b0b03c727ab44 (patch) | |
| tree | c0d87ca6052d1affa96432dfcbbe1122fa5efddb /docs/ref/forms | |
| parent | cdfefbec721b59695e28e5992eda1cc52af48212 (diff) | |
[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 9fb0f5dddc4cf7f2d294af1bcde2c359cffd90a5 from master
Diffstat (limited to 'docs/ref/forms')
| -rw-r--r-- | docs/ref/forms/api.txt | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 4cf8e7d828..4fef753172 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -964,10 +964,20 @@ classes:: .. versionadded:: 1.7 -* It's possible to opt-out from a ``Field`` inherited from a parent class by - shadowing it. While any non-``Field`` value works for this purpose, it's - recommended to use ``None`` to make it explicit that a field is being - nullified. +* It's possible to declaratively remove a ``Field`` inherited from a parent + class by setting the name to be ``None`` on the subclass. For example:: + + >>> from django import forms + + >>> class ParentForm(forms.Form): + ... name = forms.CharField() + ... age = forms.IntegerField() + + >>> class ChildForm(ParentForm): + ... name = None + + >>> ChildForm().fields.keys() + ... ['age'] .. _form-prefix: |
