fixing more errors

parent 3c618780
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
\ No newline at end of file
from django.forms import ModelForm
from.models import Announcement
class AnnouncementForm(ModelForm):
class Meta:
model = Announcement
fields = ["announcement_title", "announcement_body", "author"]
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block content %}
<form method="POST" action="add">
{% csrf_token %}
{{ announcement_form.as_p }}
<button class="button" type="submit">Save Announcement</button>
</form>
<br>
<a href="/announcements">Back to announcement board</a>
{% endblock %}
......@@ -11,7 +11,6 @@
{% else %}
<p>No announcements are available.</p>
{% endif %}
<button type="button" onclick="location.href='add'">New Announcement</button>
{% endblock %}
......
......@@ -4,12 +4,9 @@ from . import views
app_name = "announcements"
urlpatterns = [
# announcements/
path('', views.index, name='index'),
# announcements/1/details
#announcements/1/details
path("<int:announcement_id>/details", views.details, name="details"),
# announcements/add
path("add", views.add, name="add"),
#announcements/1/reactions
# path("<int:announcement_id>/reactions", views.reactions, name="reactions"),
......
from django.http import HttpResponse, Http404
from django.shortcuts import render, redirect
import datetime
from django.shortcuts import render
from .models import Announcement, Reaction
from .forms import AnnouncementForm
# Create your views here.
def index(request):
......@@ -25,21 +23,8 @@ def details(request, announcement_id):
raise Http404("Announcement does not exist!")
return render(request, "announcements/details.html", context)
def add(request):
if request.method == "POST":
announcement_form = AnnouncementForm(request.POST)
if announcement_form.is_valid():
new_announcement = announcement_form.save()
return redirect("announcements:add")
else:
announcement_form = AnnouncementForm()
pub_date = datetime.datetime.now()
context = {
"announcement_form": announcement_form,
"pub_date": pub_date
}
return render(request, "announcements/add.html", context)
# def reactions(request, announcement_id):
......
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