Commit 978ef983 authored by Carlo Joseph Echon's avatar Carlo Joseph Echon 🐟

Changed views in announcements to display all Announcements and Reactions

parent 18c5d09d
from django.http import HttpResponse from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("This is the Announcement Board!") return HttpResponse(display_announcementboard(Announcement.objects.all()))
\ No newline at end of file
def display_announcementboard(announcement_data):
display_output = "ANNOUNCEMENTS: <br>"
for object in announcement_data:
display_output += '''
{title} by {first_name} {last_name} dated {date}:<br>
{body}<br>
Like: {like_tally}<br>
Love: {love_tally}<br>
Angry: {angry_tally}<br>
<br>
'''.format(title = object.announcement_title,
first_name = object.author.first_name,
last_name = object.author.last_name,
date = str(object.pub_date),
body = object.announcement_body,
like_tally = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Like").first().tally,
love_tally = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Love").first().tally,
angry_tally = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Angry").first().tally)
return display_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