MU
Maciej UrmańskiJuly 21, 2020, 8:12 a.m.
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.Do you like it? Share on social networks!
AD
- Akiv Doros
- Nov. 12, 2024, 1:58 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:50points,
- Rating points-4
m
- molni99
- Oct. 26, 2024, 11:37 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
m
- molni99
- Oct. 26, 2024, 11:29 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:20points,
- Rating points-10
Last comments
Evgenii LegotckoiNov. 1, 2024, 12:37 a.m.
Fb3 file reader on Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
ИМ
Django - Lesson 064. How to write a Python Markdown extension Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
Игорь МаксимовOct. 5, 2024, 5:51 p.m.
QML - Lesson 016. SQLite database and the working with it in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
Now discuss on the forum
Evgenii LegotckoiJune 25, 2024, 1:11 a.m.
t
google domain [url=https://google.com/]domain[/url] domain [http://www.example.com link title]
tonypeachey1Nov. 15, 2024, 5:04 p.m.
NSProjectJune 4, 2022, 1:49 p.m.
IscanderCheNov. 1, 2024, 1:43 a.m.
Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…
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. :)