Commit 92b62429 authored by Julia Anishka's avatar Julia Anishka

fixed url format of details, add and edit announcement

parent 8aa8eb3c
from django.db import models from django.db import models
from django.urls import reverse
from dashboard.models import WidgetUser from dashboard.models import WidgetUser
...@@ -6,10 +7,13 @@ class Announcement(models.Model): ...@@ -6,10 +7,13 @@ class Announcement(models.Model):
title = models.CharField(max_length = 50) title = models.CharField(max_length = 50)
body = models.TextField(max_length = 700, null = True, blank = True) body = models.TextField(max_length = 700, null = True, blank = True)
author = models.ForeignKey(WidgetUser, on_delete = models.CASCADE) author = models.ForeignKey(WidgetUser, on_delete = models.CASCADE)
pub_datetime = models.DateTimeField('publication date and time') pub_datetime = models.DateTimeField('publication date and time', auto_now_add=True)
def __str__(self): def __str__(self):
return self.title return self.title
def get_absolute_url(self):
return reverse('announcementboard:announcement-details', kwargs={'pk': self.pk})
class Reaction(models.Model): class Reaction(models.Model):
class Choices(models.TextChoices): class Choices(models.TextChoices):
......
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %} {{ announcement.title }} {% endblock %} {% block title %} {{ announcement.title }} {% endblock %}
{% block header %} {% block header %}
<h1> {{ announcement.title }} </h1> <h1> {{ announcement.title }} </h1>
{% endblock %} {% endblock %}
{% block body %} {% block body %}
...@@ -14,6 +14,5 @@ ...@@ -14,6 +14,5 @@
<li>Love: {{ tallies.love|default:0 }}</li> <li>Love: {{ tallies.love|default:0 }}</li>
<li>Angry: {{ tallies.angry|default:0 }}</li> <li>Angry: {{ tallies.angry|default:0 }}</li>
</ul> </ul>
<a href="{% url 'announcementboard:announcement-edit' announcement.id %}"> Edit Announcement </a>
<a href="{{ announcement.get_absolute_url }}edit"> Edit Announcement </a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</ul> </ul>
</div> </div>
<div> <div>
<a href="/announcements/announcements/add/"> New Announcement </a> <a href="/announcements/add/"> New Announcement </a>
</div> </div>
<a href="/dashboard/"> Dashboard </a> <a href="/dashboard/"> Dashboard </a>
<a href="/forum/"> Forum </a> <a href="/forum/"> Forum </a>
......
...@@ -5,9 +5,9 @@ from .views import (AnnouncementsDetailView, AnnouncementsUpdateView, Announceme ...@@ -5,9 +5,9 @@ from .views import (AnnouncementsDetailView, AnnouncementsUpdateView, Announceme
urlpatterns = [ urlpatterns = [
path('', views.announcement_view, name='announcements'), path('', views.announcement_view, name='announcements'),
path('announcements/<int:pk>/details/', AnnouncementsDetailView.as_view(), name='announcement-details'), path('<int:pk>/details/', AnnouncementsDetailView.as_view(), name='announcement-details'),
path('announcements/add/', AnnouncementsCreateView.as_view(), name='announcement-add'), path('add/', AnnouncementsCreateView.as_view(), name='announcement-add'),
path('announcements/<int:pk>/details/edit/', AnnouncementsUpdateView.as_view(), name='announcement-edit') path('<int:pk>/edit/', AnnouncementsUpdateView.as_view(), name='announcement-edit'),
] ]
app_name = 'announcementboard' app_name = 'announcementboard'
\ 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