From 2ee73c2f4e6f0822892c97998325faeeee408255 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sun, 9 May 2010 06:50:39 +0000 Subject: [PATCH] [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 --- docs/ref/contrib/admin/index.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index f7ad31c15ef87..251f85547f27d 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -823,6 +823,20 @@ return a subset of objects for this foreign key field based on the user:: This uses the ``HttpRequest`` instance to filter the ``Car`` foreign key field to only the cars owned by the ``User`` instance. +.. method:: ModelAdmin.queryset(self, request): + +The ``queryset`` method on a ``ModelAdmin`` returns a +:class:`~django.db.models.QuerySet` of all model instances that can be +edited by the admin site. One use case for overriding this method is +to show objects owned by the logged-in user:: + + class MyModelAdmin(admin.ModelAdmin): + def queryset(self, request): + qs = super(self, MyModelAdmin).queryset(request) + if request.user.is_superuser: + return qs + return qs.filter(author=request.user) + Other methods ~~~~~~~~~~~~~