[英]How to Count quantity of my QuerySet. Django
Well, i have the following function:好吧,我有以下 function:
employees_birthday = Employees.objects.filter(EmployeeDataNasc__gte=first_day, EmployeeDataNasc__lte=last_day)
It serves to return employees born between the dates.它用于返回在日期之间出生的员工。 She returns:
她回来了:
<QuerySet [<Employees: Alberto Santos>, <Employees: Josney Arman>]>
But, I would just like to display the number of employees in the QuerySet, ie make a Count function.但是,我只想显示 QuerySet 中的员工数量,即计算 function。
Can someone help me with the syntax?有人可以帮我语法吗?
If you are going to display the Employees
anyway, then it is better to use len(…)
.如果无论如何都要显示
Employees
,那么最好使用len(…)
。 This will fetch the Employees
in memory, and return the number of Employees
:这将获取 memory 中的
Employees
,并返回Employees
的数量:
employees_birthday = Employees.objects.filter(
EmployeeDataNasc__range=(first_day, last_day)
)
number_of_birthdays =
len(employee_birthdays
)
if you however plan to only render the number of Employees
, then you use .count()
[Django-doc] , since this will prevent fetching the items in memory.但是,如果您打算只呈现
Employees
的数量,那么您可以使用.count()
[Django-doc] ,因为这将阻止获取 memory 中的项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.