Commit 5d13d77d authored by Emilio Gentolia's avatar Emilio Gentolia

changed function to class view for announcements

parent ad41407b
from django.http import HttpResponse from django.shortcuts import render
from .models import Announcement, Reaction from django.views import View
from django.views.generic.detail import DetailView
from .models import Announcement
# View for announcements page.
def index(request):
return HttpResponse(display_announcementboard(Announcement.objects.all(), Reaction.objects.all()))
def display_announcementboard(announcement_data, reaction_data): class AnnouncementView(View):
display_output = "ANNOUNCEMENTS: <br>" def get(self, request):
for object in announcement_data: objects_set = {
announcement_title = object.announcement_title "all_announcements": [obj for obj in Announcement.objects.all().order_by('last_name')]
first_name = object.author.first_name }
last_name = object.author.last_name return render(request, 'homepage/index.html', objects_set)
pub_date = str(object.pub_date)
announcement_body = object.announcement_body
like_count = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Like").first().tally class AnnouncementDetailView(DetailView):
love_count = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Love").first().tally model = Announcement
angry_count = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Angry").first().tally
display_output += f'''
{announcement_title} by {first_name} {last_name} dated {pub_date}:<br>
{announcement_body}<br>
Like: {like_count}<br>
Love: {love_count}<br>
Angry: {angry_count}<br>
<br>
'''
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