Answer the question
In order to leave comments, you need to log in
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} оценки'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question