How to achieve this manipulation in the Django-adm

2019-08-09 06:45发布

When the user clicks on 'Users - Pending' in the picture below:

enter image description here

he should be redirected to the page with the filter by staff status set to 'No' and not 'All' which is the default. The url of that, which appears on clicking 'No' is this http://127.0.0.1:8000/admin/auth/pending/?is_staff__exact=0:

enter image description here

What do I need to change where to achieve this?

2条回答
冷血范
2楼-- · 2019-08-09 07:12

Add this def in your 'UserPendingAdmin' class:

def get_queryset(self, request):
    """Limit list display to instances that belong to the request's user."""
    qs = super(UserPendingAdmin, self).get_queryset(request)
    # this if you want superuser to see all
    if request.user.is_superuser:
        return qs
    return qs.filter(user__staff_status = False)
查看更多
混吃等死
3楼-- · 2019-08-09 07:15
def get_queryset(self, request):

q = super(UserAdmin, self).get_queryset(request)
if request.user.is_superuser:
    return q
return q.filter(is_staff = False)
查看更多
登录 后发表回答