Commit 8aa8eb3c authored by Julia Anishka's avatar Julia Anishka

updated views, url and created template for announcement details

parent 37a62fde
{% extends 'base.html' %}
{% block title %} {{ announcement.title }} {% endblock %}
{% block header %}
<h1> {{ announcement.title }} </h1>
{% endblock %}
{% block body %}
<h4> by {{ announcement.author.first_name }} {{ announcement.author.last_name }}</h4>
<h4>{{ announcement.pub_datetime|date:'m/d/Y, H:i A'}}</h4>
<h4>{{ announcement.body }}</h4>
<ul>
<li>Like: {{ tallies.like|default:0 }}</li>
<li>Love: {{ tallies.love|default:0 }}</li>
<li>Angry: {{ tallies.angry|default:0 }}</li>
</ul>
<a href="{{ announcement.get_absolute_url }}edit"> Edit Announcement </a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from . import views
from .views import (AnnouncementsCreateView, AnnouncementsUpdateView,
from .views import (AnnouncementsDetailView, AnnouncementsUpdateView, AnnouncementsCreateView
)
urlpatterns = [
path('', views.announcement_view, name='announcements'),
path('announcements/<int:pk>/details/', AnnouncementsDetailView.as_view(), name='announcement-details'),
path('announcements/add/', AnnouncementsCreateView.as_view(), name='announcement-add'),
path('announcements/<int:pk>/details/edit/', AnnouncementsUpdateView.as_view(), name='announcement-edit'),
path('announcements/<int:pk>/details/edit/', AnnouncementsUpdateView.as_view(), name='announcement-edit')
]
app_name = 'announcementboard'
\ No newline at end of file
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Announcement, Reaction
......@@ -20,4 +21,26 @@ class AnnouncementsCreateView(CreateView):
class AnnouncementsUpdateView(UpdateView):
model = Announcement
template_name = 'announcementboard/announcement-edit.html'
fields = '__all__'
\ No newline at end of file
fields = '__all__'
class AnnouncementsDetailView(DetailView):
model = Announcement
template_name = 'announcementboard/announcement-details.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
reactions = Reaction.objects.filter(announcement=self.object)
tallies = {
'like': 0,
'love': 0,
'angry': 0
}
for reaction in reactions:
if reaction.name == 'Like':
tallies['like'] += reaction.tally
elif reaction.name == 'Love':
tallies['love'] += reaction.tally
elif reaction.name == 'Angry':
tallies['angry'] += reaction.tally
context['tallies'] = tallies
return context
\ 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