Commit 46a9f2ba authored by Alia Lawraine Olay's avatar Alia Lawraine Olay

Added form to create new announcement

parent 7afc1b6a
from django import forms
from .models import Announcement
class AnnouncementForm(forms.ModelForm):
class Meta:
model = Announcement
fields = [
'announcement_title',
'announcement_body',
'author',
]
\ No newline at end of file
from django.urls import path
from .views import announcement_list_view, announcement_detail_view
from .views import AnnouncementListView, AnnouncementCreateView, announcement_detail_view
urlpatterns = [
# path('', index, name='index')
path('', announcement_list_view, name='announcement-list'),
path('<int:pk>/details', announcement_detail_view, name='announcement-detail'),
path('', AnnouncementListView.as_view(), name='announcement-list'),
path('<int:pk>/details/', announcement_detail_view, name='announcement-detail'),
path('add/', AnnouncementCreateView.as_view(), name='announcement-create'),
]
app_name = "announcementboard"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.urls import reverse
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView
from .models import Announcement
......@@ -8,6 +9,12 @@ from .models import Announcement
class AnnouncementListView(ListView):
queryset = Announcement.objects.order_by('-pub_date')
class AnnouncementCreateView(CreateView):
model = Announcement
fields = '__all__'
def get_success_url(self):
return reverse('announcementboard:announcement-list')
def announcement_detail_view(request, pk):
announcement = Announcement.objects.get(pk=pk)
......
......@@ -27,4 +27,6 @@
Like: {{ count_like }}<br>
Love: {{ count_love }}<br>
Angry: {{ count_angry }}
<br><br><br>
<a href="{% url 'announcementboard:announcement-list' %}">Back to Announcement Board</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Create Announcement{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'announcementboard/css/detail_styles.css' %}">
{% endblock %}
{% block content %}
<h1>New Announcement</h1>
<form method="POST">
{% csrf_token %}
<label for="{{ form.announcement_title.id_for_label }}">Announcement Title</label><br>
{{ form.announcement_title }}<br><br><br>
<label for="{{ form.announcement_body.id_for_label }}">Announcement Body</label><br>
{{ form.announcement_body }}<br><br><br>
<label for="{{ form.authot.id_for_label }}">Author</label><br>
{{ form.author }}<br><br>
<input type="submit" value="Save Announcement">
</form>
<a href="{% url 'announcementboard:announcement-list' %}">Back to Announcement Board</a>
{% endblock %}
......@@ -18,4 +18,6 @@
</a>
</li>
{% endfor %}
<br><br><br>
<a href="{% url 'announcementboard:announcement-create' %}">Add New Announcement</a>
{% endblock %}
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