Commit 859a772a authored by Julia Anishka's avatar Julia Anishka

created views for announcement board

parent 4a69aebf
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
from .models import Announcement, Reaction
def index(request):
all_announcements = Announcement.objects.all()
all_reactions = Reaction.objects.all()
welcomeMessage = 'Widget\'s Announcement Board<br><br>Announcements:<br>'
response = ''
for announcement in all_announcements:
reactions = ''
reactions_list = {'Like':0, 'Love':0, 'Angry':0}
for reaction in all_reactions:
if reaction.announcement.title == announcement.title:
reactions_list[reaction.name] = reaction.tally
keys = list(reactions_list.keys())
for key in keys:
reactions += key + ': ' + str(reactions_list[key]) + '<br>'
datetime = announcement.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
author = announcement.author.first_name + ' '+ announcement.author.last_name
response += announcement.title + ' by ' + author + ' published ' + datetime
response += ':' + '<br>' + announcement.body + '<br>' + reactions + '<br>'
return HttpResponse(welcomeMessage + response)
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