Ticket #10712: 10712.diff

File 10712.diff, 962 bytes (added by timo, 6 years ago)

document case #1

  • docs/ref/contrib/admin/index.txt

     
    820820This uses the ``HttpRequest`` instance to filter the ``Car`` foreign key field
    821821to only the cars owned by the ``User`` instance.
    822822
     823.. method:: ModelAdmin.queryset(self, request):
     824
     825The ``queryset`` method on a ``ModelAdmin`` returns a
     826:class:`~django.db.models.QuerySet` of all model instances that can be edited
     827by the admin site. One use case for overriding this method is to show objects
     828owned by the logged-in user::
     829
     830    class MyModelAdmin(admin.ModelAdmin):
     831        def queryset(self, request):
     832            qs = super(self, MyModelAdmin).queryset(request)
     833            if request.user.is_superuser:
     834                return qs
     835            return qs.filter(author=request.user)
     836
    823837Other methods
    824838~~~~~~~~~~~~~
    825839
Back to Top