Commit 3b5393e1 authored by Agu Syquia's avatar Agu Syquia

Updated views.py

Finalized the for loops and HttpResponse
parent 6f6a1ca6
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here.
def announcement_boardIndex(request):
announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
announcement_board_output = "Widget’s Announcement Board <br><br> Announcements: <br>"
for announcement in announcements:
datetime = announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p")
announcement_board_output += (announcement.title + " by " + announcement.author.first_name +
" " + announcement.author.last_name + " published " + datetime +
": <br>" + announcement.body + "<br>"
)
like_tally = 0
love_tally = 0
angry_tally = 0
for reaction in reactions:
if reaction.announcement.title == announcement.title:
if reaction.name == "Like":
like_tally = reaction.tally
elif reaction.name == "Love":
love_tally = reaction.tally
elif reaction.name == "Angry":
angry_tally = reaction.tally
announcement_board_output = (announcement_board_output + "Like: " + str(like_tally) + "<br>Love: " +
str(love_tally) + "<br>Angry: " + str(angry_tally) + "<br><br>")
return HttpResponse(announcement_board_output)
\ 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