Commit 4c8d3031 authored by Bryan Carlo Guanlao's avatar Bryan Carlo Guanlao

Changed reactions choices field

Moved the list to the reaction class and defined a constant for
each value
parent be7597e3
from django.db import models from django.db import models
from homepage.models import WidgetUser from homepage.models import WidgetUser
REACTION_CHOICES = [('Like', 'Like'), ('Love', 'Love'), ('Hate', 'Hate')]
class Announcement(models.Model): class Announcement(models.Model):
author = models.ForeignKey( author = models.ForeignKey(
...@@ -22,6 +20,15 @@ class Reaction(models.Model): ...@@ -22,6 +20,15 @@ class Reaction(models.Model):
Announcement, Announcement,
on_delete=models.CASCADE, on_delete=models.CASCADE,
) )
LIKE = 'Like'
LOVE = 'Love'
ANGRY = 'Angry'
REACTION_CHOICES = [
(LIKE, 'Like'),
(LOVE, 'Love'),
(ANGRY, 'Angry')
]
reaction_name = models.CharField( reaction_name = models.CharField(
max_length=10, max_length=10,
choices=REACTION_CHOICES, choices=REACTION_CHOICES,
......
...@@ -7,13 +7,13 @@ def get_reactions(a): ...@@ -7,13 +7,13 @@ def get_reactions(a):
reaction = '' reaction = ''
like = Reaction.objects.filter(reaction_name='Like', announcement=a) like = Reaction.objects.filter(reaction_name='Like', announcement=a)
love = Reaction.objects.filter(reaction_name='Love', announcement=a) love = Reaction.objects.filter(reaction_name='Love', announcement=a)
hate = Reaction.objects.filter(reaction_name='Hate', announcement=a) angry = Reaction.objects.filter(reaction_name='Angry', announcement=a)
for l in like: for l in like:
reaction += '{}: '.format(l) + '{}'.format(l.tally) + '<br>' reaction += '{}: '.format(l) + '{}'.format(l.tally) + '<br>'
for l in love: for l in love:
reaction += '{}: '.format(l) + '{}'.format(l.tally) + '<br>' reaction += '{}: '.format(l) + '{}'.format(l.tally) + '<br>'
for h in hate: for a in angry:
reaction += '{}: '.format(h) + '{}'.format(h.tally) + '<br>' reaction += '{}: '.format(a) + '{}'.format(a.tally) + '<br>'
return reaction return reaction
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment