Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #10712 -- Added documentation for the queryset() method…

… on ModelAdmin. Thanks to mrts for the report, and timo for the patch.

Backport of r13170 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@13176 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2ee73c2f4e6f0822892c97998325faeeee408255 1 parent 5d75102
Russell Keith-Magee authored

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

  1. 14  docs/ref/contrib/admin/index.txt
14  docs/ref/contrib/admin/index.txt
@@ -823,6 +823,20 @@ return a subset of objects for this foreign key field based on the user::
823 823
 This uses the ``HttpRequest`` instance to filter the ``Car`` foreign key field
824 824
 to only the cars owned by the ``User`` instance.
825 825
 
  826
+.. method:: ModelAdmin.queryset(self, request):
  827
+
  828
+The ``queryset`` method on a ``ModelAdmin`` returns a
  829
+:class:`~django.db.models.QuerySet` of all model instances that can be
  830
+edited by the admin site. One use case for overriding this method is
  831
+to show objects owned by the logged-in user::
  832
+
  833
+    class MyModelAdmin(admin.ModelAdmin):
  834
+        def queryset(self, request):
  835
+            qs = super(self, MyModelAdmin).queryset(request)
  836
+            if request.user.is_superuser:
  837
+                return qs
  838
+            return qs.filter(author=request.user)
  839
+
826 840
 Other methods
827 841
 ~~~~~~~~~~~~~
828 842
 

0 notes on commit 2ee73c2

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