summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Bistuer <loic.bistuer@sixmedia.com>2013-11-22 19:55:02 +0700
committerTim Graham <timograham@gmail.com>2013-11-22 19:48:54 -0500
commit033b26173bbcdf55294f0a019c61cbf6341582b2 (patch)
tree2ce4e68dd02cbe1764ce00d47b9a5f4d445b75b4
parentc456ea4ec88a0ab43179ccfe811cb6d8483a1db8 (diff)
Improved docs for ModelFormSet.clean().
-rw-r--r--docs/topics/forms/modelforms.txt18
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
index 79a5dbda9c..d8d1c106f8 100644
--- a/docs/topics/forms/modelforms.txt
+++ b/docs/topics/forms/modelforms.txt
@@ -943,6 +943,24 @@ class's ``clean`` method::
# your custom formset validation
...
+Also note that by the time you reach this step, individual model instances
+have already been created for each ``Form``. Modifying a value in
+``form.cleaned_data`` is not sufficient to affect the saved value. If you wish
+to modify a value in ``ModelFormSet.clean()`` you must modify
+``form.instance``::
+
+ from django.forms.models import BaseModelFormSet
+
+ class MyModelFormSet(BaseModelFormSet):
+ def clean(self):
+ super(MyModelFormSet, self).clean()
+
+ for form in self.forms:
+ name = form.cleaned_data['name'].upper()
+ form.cleaned_data['name'] = name
+ # update the instance value.
+ form.instance.name = name
+
Using a custom queryset
-----------------------