Commit d815dee3 authored by Jayson Lim's avatar Jayson Lim

created announcement-add.html and implemented CreateView

parent bed1aa58
......@@ -22,7 +22,7 @@ class Announcement(models.Model):
return self.pub_datetime.strftime('%m/%d/%Y, %I:%M %p')
def get_absolute_url(self):
return reverse('announcements:announcement-detail', kwargs={'pk': self.pk})
return reverse('announcements:announcements-detail', kwargs={'pk': self.pk})
class Reaction(models.Model):
name = models.CharField(max_length=5, choices=[('Like', 'Like'),
......
{% extends 'base.html' %}
{% load static %}
{% block title %} Add Announcement {% endblock %}
{% block heading %}
<h1> Add a new announcement: </h1>
{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<div class="separator-bar"></div><br>
<input type="submit" value="Save New Post">
</form>
{% endblock %}
......@@ -12,6 +12,5 @@
<p>
{{ reaction.name }}: {{ reaction.tally }}
</p>
<br>
{% endfor %}
{% endblock %}
\ No newline at end of file
......@@ -16,4 +16,6 @@
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
<hr>
<button onclick="window.location.href='{% url 'announcements:announcements-add' %}'">New Announcement</button>
{% endblock %}
from django.urls import path
from .views import index, AnnouncementsDetailView
from .views import index, AnnouncementsDetailView, AnnouncementsCreateView
urlpatterns = [
path('', index, name='index'),
path('announcements/<int:pk>/details', AnnouncementsDetailView.as_view(), name='announcements-detail'),
path('announcements/add', AnnouncementsCreateView.as_view(), name = 'announcements-add'),
]
......
......@@ -12,3 +12,8 @@ def index(request):
class AnnouncementsDetailView(DetailView):
model = Announcement
template_name = 'announcements/announcement-details.html'
class AnnouncementsCreateView(CreateView):
model = Announcement
template_name = 'announcements/announcement-add.html'
fields = ["title", "body", "author"]
\ 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