0
我的代碼是更新環境參數值
class Leads(LoginRequiredMixin, ListView):
def get_queryset(self):
q = self.request.GET.get('q', "all")
if q == "customer":
qs = alllead.objects.filter(isCustomer="yes")
elif q == "lead":
qs = alllead.objects.filter(isCustomer="no")
else:
qs = self.queryset
return qs
def get_context_data(self, **kwargs):
context = super(Leads, self).get_context_data(**kwargs)
count = self.queryset.count()
context['count'] = count or "000"
return context
,所以我過濾我的查詢集,也是我需要設置記錄計數作爲上下文參數「計數」 ,但記錄的數量不更新 ,所以我改變了我的代碼
def get_queryset(self):
q = self.request.GET.get('q', "all")
if q == "customer":
qs = alllead.objects.filter(isCustomer="yes")
elif q == "lead":
qs = alllead.objects.filter(isCustomer="no")
else:
qs = self.queryset
return qs
def get_context_data(self, **kwargs):
context = super(Leads, self).get_context_data(**kwargs)
q = self.request.GET.get('q', "none")
if q == "customer":
count = alllead.objects.filter(isCustomer="yes").count()
elif q == "lead":
count = alllead.objects.filter(isCustomer="no").count()
else:
count = self.queryset.count()
context['count'] = count or "000"
return context
我覺得我重複代碼,這是不這樣做的正確方法。 任何人都可以建議我更新
context['count'] = qs.count()
#inside get_queryset()
非常感謝你,我改變了我的模板 '{{object_list.count | default:「0」}}' 但它只顯示25?哪些是當前分頁對象? –
'count = context ['alllead_list']。count()'這個sollution也給出當前分頁對象的數量25 –
'{{paginator.count}}'適用於我。 它解決了我的問題只在一行 –