Django administration panel filter list

119 views Asked by At

I have my django model: Post

Any Post has an author (User|Admin)

I would to add post's administration in my Django administration panel but I would to show in Posts list ONLY posts with author=Admin.

Is possible this?

1

There are 1 answers

0
alTus On BEST ANSWER

Generally speaking I would say that it's better to create a custom view for this purpose (in a public section of the site). But if you prefer to use admin then you can try get_queryset method. For example if you want to show all posts to admins and their own posts for simple users it would be smth like this (copied from official docs link above):

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