Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1049 -- Documented the need to implement flatten_data() in som…

…e cases for custom

ChangeManipulator replacements. Thanks, Michael Radziej.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@4711 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5295f54b3cf30d7cf11bffe9ca66230c205291cc 1 parent db03c7f
Malcolm Tredinnick authored March 12, 2007

Showing 1 changed file with 21 additions and 0 deletions. Show diff stats Hide diff stats

  1. 21  docs/forms.txt
21  docs/forms.txt
@@ -417,6 +417,27 @@ Here's a simple function that might drive the above form::
417 417
         form = forms.FormWrapper(manipulator, new_data, errors)
418 418
         return render_to_response('contact_form.html', {'form': form})
419 419
 
  420
+Implementing ``flatten_data`` for custom manipulators
  421
+------------------------------------------------------
  422
+
  423
+It is possible (although rarely needed) to replace the default automatically
  424
+created manipulators on a model with your own custom manipulators. If you do
  425
+this and you are intending to use those models in generic views, you should
  426
+also define a ``flatten_data`` method in any ``ChangeManipulator`` replacement.
  427
+This should act like the default ``flatten_data`` and return a dictionary
  428
+mapping field names to their values, like so::
  429
+
  430
+    def flatten_data(self):
  431
+        obj = self.original_object
  432
+        return dict(
  433
+            from = obj.from,
  434
+            subject = obj.subject,
  435
+            ...
  436
+        )
  437
+
  438
+In this way, your new change manipulator will act exactly like the default
  439
+version.
  440
+
420 441
 ``FileField`` and ``ImageField`` special cases
421 442
 ==============================================
422 443
 

0 notes on commit 5295f54

Please sign in to comment.
Something went wrong with that request. Please try again.