Commit 39ee8f3a authored by Titia de Castro's avatar Titia de Castro

added get methods for announcement and reaction models

parent 98d5040b
...@@ -12,6 +12,18 @@ class Announcement(models.Model): ...@@ -12,6 +12,18 @@ class Announcement(models.Model):
def __str__(self): def __str__(self):
return self.announcement_title return self.announcement_title
def getAnnouncement(self):
return '{} by {} {} dated {}:<br>{}<br>Like: {}<br>Love: {}<br>Angry: {}<br>'.format(
self.announcement_title,
self.author.first_name,
self.author.last_name,
self.pub_date,
self.announcement_body,
self.reactions.get(reaction_name="Like").getTally(),
self.reactions.get(reaction_name="Love").getTally(),
self.reactions.get(reaction_name="Angry").getTally()
)
class Reaction(models.Model): class Reaction(models.Model):
class ReactionNames(models.TextChoices): class ReactionNames(models.TextChoices):
LIKE = 'Like' LIKE = 'Like'
...@@ -24,3 +36,6 @@ class Reaction(models.Model): ...@@ -24,3 +36,6 @@ class Reaction(models.Model):
def __str__(self): def __str__(self):
return '{} {} reactions'.format(self.announcement.announcement_title, self.reaction_name) return '{} {} reactions'.format(self.announcement.announcement_title, self.reaction_name)
def getTally(self):
return self.tally
\ No newline at end of file
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