count items in a model django rest

Solutions on MaxInterview for count items in a model django rest by the best coders in the world

showing results for - "count items in a model django rest"
Paola
14 Jul 2016
1CustomerInformation.objects.annotate(lead_count=Count('status',filter=Q(status="lead"))).annotate(client_count=Count('status',filter=Q(status="client")))
2
Brooklyn
24 Nov 2020
1class CustomerInformation(models.Model):
2
3    status = (
4        ('lead', 'Lead'),
5        ('client', 'Client'),
6    )
7
8    customer_name = models.CharField(max_length=100)
9    status = models.CharField(max_length=100, choices=status, default='lead')
10    creator = models.ForeignKey('UserProfile', related_name='customers', on_delete=models.CASCADE, null=True, blank=True)
11    created_date = models.DateField(default=timezone.now)
12