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