In my user table i have many user type and status (pending = 0,1 = approved). i am getting the count like.
user = {}
user['pending'] = User.objects.filter(type=3,status='0').count()
user['approved'] = User.objects.filter(type=3,status='2').count()
user['blocked'] = User.objects.filter(type=3,status='4').count()
print(user)
Using this i am getting result in this way like : {'pending': 0, 'approved': 1, 'blocked': 0} what actually i need is i want this same result through a single query can any one please help me related this ?? thanks in advance
你可以use ^{} aggregation
result
将是一个带有status
和count
字段的QuerySet
然后,我们从
QuerySet
创建一个dict
,然后重命名键以获得所需的字典相关问题 更多 >
编程相关推荐