Author: russellm
Date: 2010-08-07 09:56:16 -0500 (Sat, 07 Aug 2010)
New Revision: 13552

Modified:
   django/trunk/docs/ref/contrib/admin/index.txt
Log:
Fixed #11882 -- Added documentation for formfield_for_manytomany. Thanks to Rob 
Hudson, timo and Simon Meers for their work on the patch.

Modified: django/trunk/docs/ref/contrib/admin/index.txt
===================================================================
--- django/trunk/docs/ref/contrib/admin/index.txt       2010-08-07 14:55:54 UTC 
(rev 13551)
+++ django/trunk/docs/ref/contrib/admin/index.txt       2010-08-07 14:56:16 UTC 
(rev 13552)
@@ -869,12 +869,27 @@
         def formfield_for_foreignkey(self, db_field, request, **kwargs):
             if db_field.name == "car":
                 kwargs["queryset"] = Car.objects.filter(owner=request.user)
-                return db_field.formfield(**kwargs)
             return super(MyModelAdmin, 
self).formfield_for_foreignkey(db_field, request, **kwargs)
 
 This uses the ``HttpRequest`` instance to filter the ``Car`` foreign key field
-to only the cars owned by the ``User`` instance.
+to only display the cars owned by the ``User`` instance.
 
+.. method:: ModelAdmin.formfield_for_manytomany(self, db_field, request, 
**kwargs)
+
+.. versionadded:: 1.1
+
+Like the ``formfield_for_foreignkey`` method, the ``formfield_for_manytomany``
+method can be overridden to change the default formfield for a many to many
+field. For example, if an owner can own multiple cars and cars can belong
+to multiple owners -- a many to many relationship -- you could filter the
+``Car`` foreign key field to only display the cars owned by the ``User``::
+
+    class MyModelAdmin(admin.ModelAdmin):
+        def formfield_for_manytomany(self, db_field, request, **kwargs):
+            if db_field.name == "cars":
+                kwargs["queryset"] = Car.objects.filter(owner=request.user)
+            return super(MyModelAdmin, 
self).formfield_for_manytomany(db_field, request, **kwargs)
+
 .. method:: ModelAdmin.queryset(self, request)
 
 The ``queryset`` method on a ``ModelAdmin`` returns a

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to