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'
...@@ -23,4 +35,7 @@ class Reaction(models.Model): ...@@ -23,4 +35,7 @@ class Reaction(models.Model):
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, related_name='reactions') announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, related_name='reactions')
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)
\ No newline at end of file
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