Updated views.py and models.py to display announcements

parent 2f50125c
......@@ -18,7 +18,10 @@ class Reaction(models.Model):
max_length=5,
choices=REACTION_CHOICES,
)
tally = models.AutoField(primary_key=True)
tally = 1
def __str__(self):
return '{}'.format(self.reaction_name)
class Announcement(models.Model):
......@@ -28,5 +31,7 @@ class Announcement(models.Model):
author = models.ForeignKey(
'homepage.WidgetUser',
on_delete=models.CASCADE,
#related_name='author'
)
\ No newline at end of file
)
def __str__(self):
return '{}'.format(self.announcement_title)
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from . import models
from .models import Announcement, Reaction
def announcements(request):
def index(request):
return HttpResponse('This is the Announcement Board!')
def announcements(request):
all_announcements = models.Announcement.objects.all()
#all_reactions = models.Reaction.objects.all()
final_output = ''
for i in all_announcements:
title = i.announcement_title
body = i.announcement_body
date = i.pub_date
last_name = i.author.last_name
first_name = i.author.first_name
like_tally = Reaction.objects.filter(reaction_name='Like', announcement=i).count()
love_tally = Reaction.objects.filter(reaction_name='Love', announcement=i).count()
angry_tally = Reaction.objects.filter(reaction_name='Angry', announcement=i).count()
output = (title+' by '+first_name+' '+last_name+' dated '+date+':<br>'
+body+'<br>'
+'Like: '+like_tally+'<br>'
+'Love: '+love_tally+'<br>'
+'Angry: '+angry_tally)
final_output += output +'<br><br>'
return HttpResponse('<h1>ANNOUNCEMENTS: </h1>' + final_output)
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