“Policz elementy w modelu Django Rest” Kod odpowiedzi

Policz elementy w modelu Django Rest

class CustomerInformation(models.Model):

    status = (
        ('lead', 'Lead'),
        ('client', 'Client'),
    )

    customer_name = models.CharField(max_length=100)
    status = models.CharField(max_length=100, choices=status, default='lead')
    creator = models.ForeignKey('UserProfile', related_name='customers', on_delete=models.CASCADE, null=True, blank=True)
    created_date = models.DateField(default=timezone.now)
Glamorous Goldfinch

Policz elementy w modelu Django Rest

CustomerInformation.objects.annotate(lead_count=Count('status',filter=Q(status="lead"))).annotate(client_count=Count('status',filter=Q(status="client")))
Glamorous Goldfinch

Odpowiedzi podobne do “Policz elementy w modelu Django Rest”

Pytania podobne do “Policz elementy w modelu Django Rest”

Więcej pokrewnych odpowiedzi na “Policz elementy w modelu Django Rest” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu