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 homepage.models import WidgetUser
REACTION_CHOICES = [('Like', 'Like'), ('Love', 'Love'), ('Hate', 'Hate')]
class Announcement(models.Model):
author = models.ForeignKey(
......@@ -22,6 +20,15 @@ class Reaction(models.Model):
Announcement,
on_delete=models.CASCADE,
)
LIKE = 'Like'
LOVE = 'Love'
ANGRY = 'Angry'
REACTION_CHOICES = [
(LIKE, 'Like'),
(LOVE, 'Love'),
(ANGRY, 'Angry')
]
reaction_name = models.CharField(
max_length=10,
choices=REACTION_CHOICES,
......
......@@ -7,13 +7,13 @@ def get_reactions(a):
reaction = ''
like = Reaction.objects.filter(reaction_name='Like', 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:
reaction += '{}: '.format(l) + '{}'.format(l.tally) + '<br>'
for l in love:
reaction += '{}: '.format(l) + '{}'.format(l.tally) + '<br>'
for h in hate:
reaction += '{}: '.format(h) + '{}'.format(h.tally) + '<br>'
for a in angry:
reaction += '{}: '.format(a) + '{}'.format(a.tally) + '<br>'
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