Change likedislike app to reaction app
Hi, I create app following the tutorial on evileg, but I do some changes.
My code:
class LikeDislikeManager(models.Manager): use_for_related_fields = True def likes(self): # We take the queryset with records greater than 0 return self.get_queryset().filter(vote__gt=0) def dislikes(self): # We take the queryset with records less than 0 return self.get_queryset().filter(vote__lt=0) def sum_rating(self): # We take the total rating return self.get_queryset().aggregate(Sum('vote')).get('vote__sum') or 0 class LikeDislike(models.Model, Activity): LIKE = 1 POWER = 1 WOW = 1 SUCCESS = 1 BLOW = 1 VOTES = ( (LIKE, 'Polubienie'), (POWER, 'Jest moc!'), (WOW, 'Wow'), (SUCCESS, 'Świetnie!'), (BLOW, 'Mózg rozwalony!'), ) vote = models.SmallIntegerField(verbose_name='Like', choices=VOTES) user = models.ForeignKey(User, verbose_name='Użytkownik polubił', on_delete=models.CASCADE) created_at = models.DateTimeField(auto_now_add=True) content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) object_id = models.PositiveIntegerField() content_object = GenericForeignKey() objects = LikeDislikeManager() @property def activity_actor_attr(self): return self.user
I don't change views.py and almost everything works fine but reaction count. I don't know how to count particural reaction. Any idea? :)

We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Timeweb
Let me recommend you the excellent hosting on which EVILEG is located.
For many years, Timeweb has been proving his stability.
For projects on Django I recommend VDS hosting
View Hosting
Hello,
In my tutorial I use +1 and -1 for Like and Dislike, because of it is very easy to get total sum, like rating. But you have different idea of reaction. You can not use +1 and -1 and make sum of these reaction.
But you can set up different types of reactions like this
And you need to write the following manager
But in this conception you don't use sum_rating . I think it is useless
Thank you! This is it. :)