Commit 732ef375 authored by N1o9r4b7e9r6to's avatar N1o9r4b7e9r6to
parents 542b31ef 838646ed
from django import forms
from .models import Announcement, Reaction
class AddAnnouncementForm(forms.ModelForm):
class Meta:
model = Announcement
fields = '__all__'
h1 { h1 {
font-family: verdana; font-family: verdana;
color: Maroon;
} }
body { body {
font-family: verdana; font-family: verdana;
background-color: hotpink; background-color: MistyRose;
color: SaddleBrown;
} }
\ No newline at end of file
{% extends "announcements/base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
{% endblock %}
{% block content %}
<h1>New Announcement</h1>
<form action="{% url 'announcements:addAnnouncement' %}" method="POST">
{% csrf_token %}
{{ add_announcement }}
<p><button class="button" type="submit">Save Announcement</button></p>
</form>
<br>
<p1>
<a href = "/announcements/">Back to Announcement Page</a>
</p1>
{% endblock %}
\ No newline at end of file
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
</p> </p>
{% endfor %} {% endfor %}
</ol> </ol>
<form action="/announcements/add">
<input type="submit" value="New Announcement" />
</form>
</body> </body>
{% endblock %} {% endblock %}
{% extends "announcements/base.html" %} {% extends "announcements/base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
{% endblock %}
{% block content %} {% block content %}
<h1> <h1>
{{announcement_details.announcement_title}} {{announcement_details.announcement_title}}
</h1> </h1>
<h2> <h4>
by by
{{announcement_details.author.first_name}} {{announcement_details.author.first_name}}
{{announcement_details.author.last_name}} {{announcement_details.author.last_name}}
dated {{announcement_details.pub_date|date:"d/m/Y"}} dated {{announcement_details.pub_date|date:"d/m/Y"}}
</h2> </h4>
<p> <p style="border:PaleVioletRed; border-width:5px; border-style:dotted; border-radius: 10px">
{{announcement_details.announcement_body}} {{announcement_details.announcement_body}}
</p> </p>
<li>Like: {{like}}</li> <li>Like: {{like}}</li>
<li>Love: {{love}}</li> <li>Love: {{love}}</li>
<li>Angry: {{angry}}</li> <li>Angry: {{angry}}</li>
<img src=http://images.gmanews.tv/webpics/2021/11/rastaman_2021_11_07_16_56_21.png> <img src=https://cdn.w600.comps.canstockphoto.com/announcement-red-vintage-isolated-seal-drawings_csp24798234.jpg>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import announcements, details from .views import AnnouncementView, details, addAnnouncement
urlpatterns = [ urlpatterns = [
path('', announcements, name='announcements'), #path('', announcements, name='announcements'),
path('announcements/<int:announcement_id>/details/', details, name='details') path('', AnnouncementView.as_view(), name='announcement'),
path('<int:announcement_id>/details/', details, name='details'),
path('add/', addAnnouncement, name='addAnnouncement')
] ]
app_name = "announcements" app_name = "announcements"
from django.shortcuts import render from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
from . import models from . import models
from .models import Announcement, Reaction from .models import Announcement, Reaction
from .forms import AddAnnouncementForm
from django.views import View
from django.views.generic.list import ListView
def index(request): class AnnouncementView(View):
return HttpResponse('This is the Announcement Board!') def get(self, request):
def announcements(request):
all_announcements = models.Announcement.objects.order_by("-id") all_announcements = models.Announcement.objects.order_by("-id")
context = { context = {
"all_announcements": all_announcements "all_announcements": all_announcements
...@@ -33,3 +34,13 @@ def details(request, announcement_id): ...@@ -33,3 +34,13 @@ def details(request, announcement_id):
"angry": angry, "angry": angry,
} }
return render(request, "announcements/details.html", context) return render(request, "announcements/details.html", context)
def addAnnouncement(request):
if request.method == 'POST':
add_announcement = AddAnnouncementForm(request.POST)
if add_announcement.is_valid():
new_announcement = add_announcement.save()
return redirect('announcements:addAnnouncement')
else:
add_announcement = AddAnnouncementForm()
return render(request, 'announcements/addAnnouncements.html', {'add_announcement': add_announcement})
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