我正在尝试在我的视图中使用if else语句,所以当我签名时,管理员和当我注销客户端时。它适用于我的queryset_list但不适用于名称。继承我的代码
def post_list(request):
today = timezone.now().date()
queryset_list = Post.objects.active()
if request.user.is_staff or request.user.is_superuser:
queryset_list = Post.objects.all()
paginator = Paginator(queryset_list, 8)
page_request_var = 'page'
page = request.GET.get(page_request_var)
try:
queryset = paginator.page(page)
except PageNotAnInteger:
queryset = paginator.page(1)
except EmptyPage:
queryset = paginator.page(paginator.num_pages)
template = "posts/post_list.html"
name = "client"
if request.user.is_staff or request.user.is_superuser:
name = "admin"
count = queryset_list.count()
so = name
hey = paginator.num_pages
context = {
"object_list": queryset,
"name": so,
"page_request_var": page_request_var,
"today": today,
"count": count,
"paginator": paginator,
"hey": hey
}