Commit e76c70e0 authored by Jayson Lim's avatar Jayson Lim

created announcement-edit.html and implemented UpdateView. Configured also the links of each page

parent d815dee3
...@@ -13,7 +13,7 @@ class Announcement(models.Model): ...@@ -13,7 +13,7 @@ class Announcement(models.Model):
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='announcements', related_name='announcements',
) )
pub_datetime = models.DateTimeField(auto_now_add=True) pub_datetime = models.DateTimeField(auto_now_add=True, editable=False)
def __str__(self): def __str__(self):
return self.title return self.title
......
...@@ -13,4 +13,7 @@ ...@@ -13,4 +13,7 @@
{{ reaction.name }}: {{ reaction.tally }} {{ reaction.name }}: {{ reaction.tally }}
</p> </p>
{% endfor %} {% endfor %}
<button onclick="window.location.href='{% url 'announcements:announcements-edit' pk=object.pk %}'">
Edit Announcement
</button>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Anouncement {% endblock %}
{% block heading %}
<h1> Edit Announcement: </h1>
{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<br>
<input type="submit" value="Save Changes to Announcement">
</form>
{% endblock %}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
{% block content %} {% block content %}
<h2> Announcements: </h2> <h2> Announcements: </h2>
<ul> <ul>
{% for object in announcements %} {% for object in announcements|dictsortreversed:"pub_datetime" %}
<li> <li>
<a href="{{ object.get_absolute_url }}"> {{ object.title }} by <a href="{{ object.get_absolute_url }}"> {{ object.title }} by
{{ object.author.first_name}} {{ object.author.last_name }} {{ object.author.first_name}} {{ object.author.last_name }}
...@@ -17,5 +17,14 @@ ...@@ -17,5 +17,14 @@
{% endfor %} {% endfor %}
</ul> </ul>
<hr> <hr>
<button onclick="window.location.href='{% url 'announcements:announcements-add' %}'">New Announcement</button> <button onclick="window.location.href='{% url 'announcements:announcements-add' %}'">
New Announcement
</button>
<div id="footer">
<a href="{% url 'dashboard:index' %}">Dashboard</a>
<a href="{% url 'forum:index' %}">Forum</a>
<a href="{% url 'assignments:homePage' %}">Assignments</a>
<a href="{% url 'widget_calendar:index' %}">Calendar</a>
</div>
{% endblock %} {% endblock %}
from django.urls import path from django.urls import path
from .views import index, AnnouncementsDetailView, AnnouncementsCreateView from .views import index, AnnouncementsDetailView, AnnouncementsCreateView, AnnouncementsUpdateView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('announcements/<int:pk>/details', AnnouncementsDetailView.as_view(), name='announcements-detail'), path('announcements/<int:pk>/details', AnnouncementsDetailView.as_view(), name='announcements-detail'),
path('announcements/add', AnnouncementsCreateView.as_view(), name = 'announcements-add'), path('announcements/add', AnnouncementsCreateView.as_view(), name = 'announcements-add'),
path('announcements/<int:pk>/edit', AnnouncementsUpdateView.as_view(), name = 'announcements-edit')
] ]
......
...@@ -16,4 +16,9 @@ class AnnouncementsDetailView(DetailView): ...@@ -16,4 +16,9 @@ class AnnouncementsDetailView(DetailView):
class AnnouncementsCreateView(CreateView): class AnnouncementsCreateView(CreateView):
model = Announcement model = Announcement
template_name = 'announcements/announcement-add.html' template_name = 'announcements/announcement-add.html'
fields = ["title", "body", "author"] fields = ["title", "body", "author"]
\ No newline at end of file
class AnnouncementsUpdateView(UpdateView):
model = Announcement
template_name = 'announcements/announcement-edit.html'
fields = '__all__'
\ 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