V
V
Villian_Os2020-12-28 13:37:53
Django
Villian_Os, 2020-12-28 13:37:53

How to get the count of something with a filter in django?

Hello, there is the following code for writing clients to the models.py master - in short, the main one:

class MasterProfile(models.Model):
    name = models.TextField('Имя', max_length=100)
    avatar = models.ImageField('Аватар', upload_to='avatarts/%Y')

class Visit(models.Model):
    created_date = models.DateField(auto_now=True)
    master = models.ForeignKey(MasterProfile, on_delete=models.DO_NOTHING)
    start_at = models.DateTimeField('Начало проведения') 
    client_name = models.CharField('Имя клиента', default='Нет имени', max_length=30)
    status_service = models.BooleanField(default=False)

I want to display a list of masters in an html template with the number of entries relative to each of the 'Visit' with 'status_service = True', but I can't figure out how to create a filter correctly, how can I implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-12-28
@bacon

annotate + filter for aggregation function https://docs.djangoproject.com/en/3.1/ref/models/q...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question