Commit 77dbe756 authored by MJoshBen's avatar MJoshBen

Implemented Per Announcement Details and edited the Models, Views and URLs accordingly

parent d064d28b
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
class Announcement(models.Model): class Announcement(models.Model):
...@@ -9,6 +10,9 @@ class Announcement(models.Model): ...@@ -9,6 +10,9 @@ class Announcement(models.Model):
def __str__(self): def __str__(self):
return '{} by {} published {}: {}'.format(self.title, self.author, self.pub_datetime, self.body) return '{} by {} published {}: {}'.format(self.title, self.author, self.pub_datetime, self.body)
def get_absolute_url(self):
return reverse('announcement:announcement-details', kwargs={'pk':self.pk})
class Reaction(models.Model): class Reaction(models.Model):
reaction_list = [("Like", "Like"), ("Heart", "Heart"), ("Angry", "Angry")] reaction_list = [("Like", "Like"), ("Heart", "Heart"), ("Angry", "Angry")]
......
{% extends 'base.html' %}
{% block title %}{{ announcement.title }}{% endblock %}
{% block content %}
<h1>{{ announcement.title }}</h1>
<h3>by {{ announcement.author }}</h3>
<h3> {{ announcement.pub_datetime }}</h3>
<h3> {{ announcement.body }}<br>
{{ reaction.name }}: {{ reaction.tally }}<br>
{{ reaction.name }}: {{ reaction.tally }}<br>
{{ reaction.name }}: {{ reaction.tally }}<br>
</h3>
{% endblock %}
{% block scripts %}
<a href="/announcements/{{ reaction.announcement.pk }}/edit"><input type="submit" value="Edit Announcement"></a>
{% endblock %}
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from .views import index from .views import index, AnnouncementDetailView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('<int:pk>/details', AnnouncementDetailView.as_view(), name='announcement-details')
] ]
app_name = "announcement" app_name = "announcement"
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views.generic.detail import DetailView
from .models import Announcement, Reaction from .models import Announcement, Reaction
def index(request): def index(request):
return render(request, 'announcement/announcement.html', {'assignments': Announcement.objects.all()}) return render(request, 'announcement/announcement.html', {'announcement': Announcement.objects.all()})
class AnnouncementDetailView(DetailView):
model = Announcement
def get(self, request, pk):
return render(request, 'announcement/announcement-details.html', {'announcement': self.model.objects.get(pk=pk)})
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