diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-05-09 06:44:52 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-05-09 06:44:52 +0000 |
| commit | f9b75db90f606d03569edcfa71792d443d7545f4 (patch) | |
| tree | 0569fdcca5d3098c267c0d38c802870581017c1d /docs | |
| parent | 3057a59ec438348f9b9d33933b1443d149a3dd0d (diff) | |
Fixed #10712 -- Added documentation for the queryset() method on ModelAdmin. Thanks to mrts for the report, and timo for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13170 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/contrib/admin/index.txt | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index aa16cf2a5f..e9784a584a 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -871,6 +871,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 ~~~~~~~~~~~~~ |
