By default Django admin site shows all records of a related model/table for viewing. How can I show only the records that meet certain criteria?
+6
A:
In your admin definition, you can define a queryset()
method that returns the queryset for that model's admin. eg:
class MyModelAdmin(admin.ModelAdmin):
def queryset(self, request):
qs = super(MyModelAdmin, self).queryset(request)
return qs.filter(user=request.user)
Then only objects with user=request.user
will be visible in the admin.
Will Hardy
2010-02-17 10:14:39
+1 I'm so happy to see this and it turned out to be so simple! Thanks!
Viet
2010-02-17 11:17:37