O
O
ooker2020-11-27 16:43:52
Django
ooker, 2020-11-27 16:43:52

How to correctly count the number of ratings for one id in the model?

Hey!
Tell me how you can get data from a certain id, let's say the number 5.
There is a model

class MasterReviewRating(models.Model):

value = models.SmallIntegerField(verbose_name='Оценка', blank=True)
master = models.ForeignKey(NewMaster, on_delete=models.CASCADE, verbose_name='Выберите мастера')

@property
 def count_four(self):
      return MasterReviewRating.objects.filter(Q(master_id=self.master_id) | Q(value=4)).count()

 def rating_count_four(self):
        if self.count_four == 0:
            return f'нет оценок'
        elif self.count_four == 1:
            return f'{self.count_four} оценка'
        else:
            return f'{self.count_four} оценки'

Now the model considers id + number of ratings. And you need to display only the master, let's say number 1 and the number of its fives.
Went through all the options, does anyone have such experience.
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question