MU
Maciej Urmański21 липня 2020 р. 08:12
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? :)
Рекомендуємо хостинг TIMEWEB
Стабільний хостинг, на якому розміщується соціальна мережа EVILEG. Для проектів на Django радимо VDS хостинг.Вам це подобається? Поділіться в соціальних мережах!
d
- dsfs
- 26 квітня 2024 р. 01:56
C++ - Тест 004. Указатели, Массивы и Циклы
- Результат:80бали,
- Рейтинг балів4
d
- dsfs
- 26 квітня 2024 р. 01:35
C++ - Тест 001. Первая программа и типы данных
- Результат:73бали,
- Рейтинг балів1
Останні коментарі
Qt Linux - Урок 001. Автозапуск програми Qt під Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
АК
Qt WinAPI - Урок 007. Робота з ICMP Ping в Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
Анатолий Кононенко04 лютого 2024 р. 22:50
EVA25 грудня 2023 р. 07:30
Boost - статичне зв'язування в проекті CMake під Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
Qt/C++ - Урок 056. Підключення бібліотеки Boost в Qt для компіляторів MinGW і MSVC Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Тепер обговоріть на форумі
BlinCT05 травня 2024 р. 02:46
BlinCT05 травня 2024 р. 02:44
Best Indian Food Restaurant In Cincinnati OH Ready to embark on a gastronomic journey like no other? Join us at App india restaurant and discover why we're renowned as the Best Indian Food Restaurant In Cincinnati OH . Whether y…
Evgenii Legotckoi02 травня 2024 р. 11:07
IscanderChe30 квітня 2024 р. 01:22
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. :)