Commit f0c42122 authored by Michael Lopez's avatar Michael Lopez

tried fixing the announcement-edit and announcement-add.html

parent b6995a3c
{% extends "base.html" %}
{% load static %}
{% block title %}
Add Announcement
{% endblock %}
......@@ -8,7 +8,7 @@ Add Announcement
<h2>Add a new announcement:</h2>
<p>
<form action='' method="POST">
<form action="{% url 'announcements:announcement_details' %}" method="post">
{% csrf_token %}
<p>Title: {{form.title}}</p><br>
<p>Body: <br> {{form.body}}</p><br>
......
......@@ -15,7 +15,6 @@
Love: {{love_count}} <br><br>
Angry: {{angry_count}}</p>
<br>
<form method="get" action="{% url 'announcements:announcement_edit' pk=object.pk %}">
<button type="submit">Edit Announcement</button>
</form>
<button> <a href="{% url 'announcements:announcement_edit' object.pk %}">Edit Announcement</a></button>
{% endblock %}
\ No newline at end of file
......@@ -2,14 +2,13 @@
{% load static %}
{% block title %} Edit Announcement {% endblock %}
{% block content %}
<h2>Edit announcement:</h2>
<p>
<form action='' method="POST">
<form method="post" action="">
{% csrf_token %}
<p>Title: {{form.title}}</p><br>
<p>Body: <br> {{form.body}}</p><br>
<p>Author: {{form.author}}</p><br>
<input type="submit" value="Save Changes to Announcement">
</form>
</p>
<input type="submit" value="Save Changes to Announcements">
</form>
{% endblock %}
{% extends "base.html" %}
{% load static %}
{% block title %}
Widget's Announcement Board
{% endblock %}
......
from django.urls import path
from .views import *
from .views import pageview, AnnouncementDetailView, AnnouncementCreateView, AnnouncementEditView
urlpatterns = [
path('', pageview, name='pageview'),
......
from .forms import *
from .forms import AddAnnouncement
from .models import Announcement, Reaction
from django.views.generic import ListView, DetailView, CreateView, UpdateView
from django.db.models import Sum
from django.shortcuts import render
from django.urls import reverse
from .models import Announcement
def pageview(request):
model_object = Announcement.objects.order_by("-pub_datetime")
......@@ -31,10 +32,7 @@ class AnnouncementCreateView(CreateView):
model = Announcement
form_class = AddAnnouncement
template_name = "announcements/announcement-add.html"
def form_valid(self, form):
response = super().form_valid(form)
form.save()
return response
def get_success_url(self):
return reverse("announcements:announcement_details", args=(self.object.pk,))
......@@ -42,10 +40,10 @@ class AnnouncementEditView(UpdateView):
model = Announcement
form_class = AddAnnouncement
template_name = "announcements/announcement-edit.html"
def form_valid(self, form):
response = super().form_valid(form)
form.save()
return response
def get_success_url(self):
return reverse("announcements:announcement_details", args=(self.object.pk,))
return reverse("announcements:announcement_details", kwargs={"pk": self.object.pk})
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