Commit 2b522e43 authored by Javi Ng's avatar Javi Ng

fixed reverse_url error, added comments to all relevant files

parent 28ff3b64
......@@ -15,8 +15,9 @@ class Announcement(models.Model):
def __str__(self):
return self.title
# get corresponding detail page
def get_absolute_url(self):
return reverse('announcement_board:announcement-details', kwargs={'pk': self.pk})
return(reverse('announcement_board:announcementdetail', kwargs={'pk': self.pk}))
class Reaction(models.Model):
......
......@@ -2,12 +2,15 @@
{% load static %}
{% block title %} Add Announcement {% endblock %}
{% block content %}
<h1> Add a new announcement: </h1>
<form method="POST">
{% csrf_token %}
{# iterate through fields in the form #}
{% for field in form%}
<b>{{ field.label }}:</b> {{ field }} <br><br>
{% endfor %}
......
......@@ -2,19 +2,29 @@
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
<h1> {{ object.title }} </h1>
<h2> {{ object.author.displayName }} </h2>
<h3> {{ object.pub_datetime|date:"m/d/Y, h:i A" }} </h3>
<p> {{ object.body }} </p> <br>
Reactions:
<ul>
{% for reaction in object.reactlist.all %}
<li> {{ reaction.name}}: {{ reaction.tally }} </li>
{% endfor %}
</ul>
{# announcement title #}
<h1> {{ object.title }} </h1>
{# announcement author using displayName method in model #}
<h2> by {{ object.author.displayName }} </h2>
{# format datetime with tags #}
<h3> {{ object.pub_datetime|date:"m/d/Y, h:i A" }} </h3>
{# announcement body #}
<p> {{ object.body }} </p> <br>
{# iterate through reactions, show name: tally #}
Reactions:
<ul>
{% for reaction in object.reactlist.all %}
<li> <b>{{ reaction.name}}:</b> {{ reaction.tally }} </li>
{% endfor %}
</ul>
<form action="../edit">
<button type="Submit">Edit Announcement</button>
</form>
<form action="../edit">
<button type="Submit">Edit Announcement</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -2,12 +2,15 @@
{% load static %}
{% block title %} Edit Announcement {% endblock %}
{% block content %}
<h1> Edit announcement: </h1>
<form method="POST">
{% csrf_token %}
{# iterate through fields #}
{% for field in form%}
<b>{{ field.label }}:</b> {{ field }} <br><br>
{% endfor %}
......
......@@ -2,22 +2,29 @@
{% load static %}
{% block title %} Widget's Announcement Board {% endblock %}
{% block content %}
<h1>Welcome to Widget's Announcement Board!</h1>
<h2>Announcements:</h2>
<ul>
{% for announcement in announcement_list %}
<li><a href="{{ announcement.get_absolute_url }}">{{ announcement.title }} by {{ announcement.author.displayName }}</a></li>
{% endfor %}
</ul>
<form action="./add">
<button type="Submit">New Announcement</button>
</form>
<h1>Welcome to Widget's Announcement Board!</h1>
<h2>Announcements:</h2>
{# iterate through announcement_list from context, use get url function to link to detail page #}
<ul>
{% for announcement in announcement_list %}
<li><a href="{{ announcement.get_absolute_url }}">{{ announcement.title }} by {{ announcement.author.displayName }}</a></li>
{% endfor %}
</ul>
<br>
<form action="./add">
<button type="Submit">New Announcement</button>
</form>
<br>
<a href="../dashboard/">Dashboard</a> <br>
<a href="../forum/">Forum</a> <br>
<a href="../assignments/">Assignments</a> <br>
<a href="../calendar/">Calendar</a> <br>
<a href="../dashboard/">Dashboard</a> <br>
<a href="../forum/">Forum</a> <br>
<a href="../assignments/">Assignments</a> <br>
<a href="../calendar/">Calendar</a> <br>
{% endblock %}
\ No newline at end of file
......@@ -2,9 +2,16 @@ from django.urls import path
from . import views
urlpatterns = [
# main page listing announcements
path("", views.announcements, name="announcements"),
# detail page for each announcement
path("<int:pk>/details/", views.AnnouncementDetailView.as_view(), name="announcementdetail"),
# create page
path("add/", views.AnnouncementCreateView.as_view(), name="announcementadd"),
# edit page for each announcement
path("<int:pk>/edit/", views.AnnouncementUpdateView.as_view(), name="announcementupdate"),
]
......
......@@ -10,7 +10,7 @@ def announcements(request):
# use context to pass announcements sorted by pubdate
context = {
"announcement_list" : Announcement.objects.all().order_by('pub_datetime'),
"announcement_list" : Announcement.objects.all().order_by('-pub_datetime'),
}
return render(request, 'announcement_board/announcements.html', context)
......
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