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 %}
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
</ul> </ul>
{% else %} {% else %}
<p>No announcements are available.</p> <p>No announcements are available.</p>
{% endif %} {% endif %}
<button type="button" onclick="location.href='add'">New Announcement</button>
{% endblock %} {% endblock %}
......
...@@ -4,13 +4,10 @@ from . import views ...@@ -4,13 +4,10 @@ from . import views
app_name = "announcements" app_name = "announcements"
urlpatterns = [ urlpatterns = [
# announcements/
path('', views.index, name='index'), path('', views.index, name='index'),
# announcements/1/details #announcements/1/details
path("<int:announcement_id>/details", views.details, name="details"), path("<int:announcement_id>/details", views.details, name="details"),
# announcements/add
path("add", views.add, name="add"),
#announcements/1/reactions #announcements/1/reactions
# path("<int:announcement_id>/reactions", views.reactions, name="reactions"), # path("<int:announcement_id>/reactions", views.reactions, name="reactions"),
#announcements/1/react #announcements/1/react
......
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.shortcuts import render, redirect from django.shortcuts import render
import datetime
from .models import Announcement, Reaction from .models import Announcement, Reaction
from .forms import AnnouncementForm
# Create your views here. # Create your views here.
def index(request): def index(request):
...@@ -25,21 +23,8 @@ def details(request, announcement_id): ...@@ -25,21 +23,8 @@ def details(request, announcement_id):
raise Http404("Announcement does not exist!") raise Http404("Announcement does not exist!")
return render(request, "announcements/details.html", context) 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): # 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