Commit f0c42122 authored by Michael Lopez's avatar Michael Lopez

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

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