0
在django 1.8如何過濾基於登錄用戶的list_filter?我無法使用django.contrib.admin中的SimpleListFilter,因爲我使用django.contrib.admin.apps.SimpleAdminConfig來使用AdminPlus註冊視圖。django1.8基於登錄的過濾器list_filter
一些代碼,我在的ModelAdmin嘗試:
def get_list_filter(self, request):
my_list_filter = super(SubCategoryAdmin, self).get_list_filter(request)
if request.user.is_superuser:
pass
else:
my_list_filter = self.get_queryset(request)
return my_list_filter
def get_queryset(self, request):
'''
Superuser has all permissions.
'''
qs = super(SubCategoryAdmin, self).get_queryset(request)
if request.user.is_superuser:
pass
else:
qs = qs.filter(
category__in=Category.objects.filter(
department__in=Department.objects.filter(
name=request.user.customuser.department.name)))
return qs
對於後代,你能否包括你認爲對你的答案有用的鏈接的相關部分?這樣,如果鏈接發生故障,更改等,您的答案將不會變得無用。非常感謝。 –