Commit 426515eb authored by Bryan Carlo Guanlao's avatar Bryan Carlo Guanlao

Added Announcement Forms

used CreateView for creating new announcements.
added templates for form.
parent 71657ded
......@@ -29,6 +29,7 @@
{% endfor %}
{% endif %}
<a href="{% url 'announcements:announcement-list' %}"><button>Go back</button></a>
{% load static %}
<img src="{% static 'announcements/tsukasa.png' %}" alt="image">
......
{% extends 'base.html' %}
{% block content %}
<h1>New Announcement</h1>
<form method="POST">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Save Announcement">
</form>
<a href="{% url 'announcements:announcement-list' %}"><button>Go back</button></a>
{% endblock content %}
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<h1>Announcements</h1>
<ul>
<div>
{% for announcement in object_list %}
<li>
<a href="{% url 'announcements:announcement-detail' announcement.id %}">
......@@ -10,5 +10,6 @@
{{announcement.pub_date|date:"d/m/Y"}}</a>
</li>
{% endfor %}
</ul>
<a href="{% url 'announcements:announcement-add' %}"><button>New Announcement</button></a>
</div>
{% endblock content %}
\ No newline at end of file
from django.urls import path
from .views import AnnouncementsDetailView, AnnouncementsListView
from .views import (
AnnouncementCreateView,
AnnouncementsDetailView,
AnnouncementsListView,
AnnouncementCreateView,
)
urlpatterns = [
path('', AnnouncementsListView.as_view(), name='announcement-list'),
path('<int:pk>/details/', AnnouncementsDetailView.as_view(),
name='announcement-detail'),
path('add/', AnnouncementCreateView.as_view(), name='announcement-add'),
]
app_name = 'announcements'
from django.shortcuts import render
from django.http import Http404, HttpRequest, HttpResponse
from .models import Announcement, Reaction, WidgetUser
from .models import Announcement
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView
from django.urls import reverse
class AnnouncementsListView(ListView):
......@@ -12,3 +13,11 @@ class AnnouncementsListView(ListView):
class AnnouncementsDetailView(DetailView):
model = Announcement
class AnnouncementCreateView(CreateView):
model = Announcement
fields = "__all__"
def get_success_url(self):
return reverse('announcements:announcement-list')
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