Commit 95ef17a0 authored by Titia de Castro's avatar Titia de Castro

added add new announcement page

parent 58634913
......@@ -20,7 +20,7 @@
<img src="{% static 'announcement1.jpg' %}" class="announcement-image" alt="Leni Robredo">
{% elif announcement.id == 2 %}
<img src="{% static 'announcement2.jpg' %}" class="announcement-image" alt="Lady Gaga in her meat dress">
{% else %}
{% elif announcement.id == 3 %}
<img src="{% static 'announcement3.jpg' %}" class="announcement-image" alt="Taylor Swift handing an award to Bruno Mars">
{% endif %}
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Announcements{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'announcements.css' %}">
{% endblock %}
{% block content %}
<h1 class="announcement-heading">New Announcement</h1>
<form action="{% url 'announcements:new-announcement' %}" method="POST">
{% csrf_token %}
{{ form.as_p }}
<button class="announcement-button" type="submit">Save Announcement</button>
</form>
<button class="announcement-button" type="submit"><a href="/announcements">Back to Announcements</a></button>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index, AnnouncementDetailView
from .views import index, AnnouncementDetailView, announcement_form
urlpatterns = [
path('', index, name='index'),
path('<int:pk>/details', AnnouncementDetailView.as_view(), name='announcement-details'),
path('<int:pk>/details/', AnnouncementDetailView.as_view(), name='announcement-details'),
path('add/', announcement_form, name='new-announcement'),
]
app_name = 'announcements'
\ No newline at end of file
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.views.generic.detail import DetailView
from .models import Announcement
from .forms import AnnouncementForm
# Create your views here.
......@@ -11,3 +12,14 @@ def index(request):
class AnnouncementDetailView(DetailView):
model = Announcement
def announcement_form(request):
if request.method == 'POST':
form = AnnouncementForm(request.POST)
if form.is_valid():
form.save()
return redirect('announcements:index')
else:
form = AnnouncementForm()
return render(request, 'announcements/new_announcement.html', {'form': form})
\ No newline at end of file
No preview for this file type
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