[Django]-How to show records related to a certain user in django admin

3👍

Maybe ModelAdmin.get_queryset() can help. You can use it to perform checks on the request.user object.

class MyModelAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        qs = super(MyModelAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(author=request.user)

Leave a comment