Commit 14898ec9 authored by Michael Lopez's avatar Michael Lopez

fixed the issues in announcement-edit and announcement-edit html files

parent f0c42122
from django import forms
from .models import Announcement
class AddAnnouncement(forms.ModelForm):
class AnnouncementForm(forms.ModelForm):
class Meta:
model = Announcement
fields = "__all__"
\ No newline at end of file
fields = ['title', 'body', 'author']
\ No newline at end of file
from django.db import models
from dashboard.models import WidgetUser
from django.urls import reverse
from django.utils import timezone
class Announcement(models.Model):
title = models.CharField(max_length=50)
body = models.TextField(max_length=1024)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
pub_datetime = models.DateTimeField(default=timezone.now)
def __str__(self):
return self.title
......
......@@ -8,13 +8,13 @@ Add Announcement
<h2>Add a new announcement:</h2>
<p>
<form action="{% url 'announcements:announcement_details' %}" method="post">
<form action="" method="post">
{% 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="Add Announcement">
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Add Announcement"/>
</form>
</p>
</p>
{% endblock %}
......@@ -2,13 +2,16 @@
{% load static %}
{% block title %} Edit Announcement {% endblock %}
{% block content %}
<form method="post" action="">
<h2>Edit announcement:</h2>
<div class="form">
<form action="" method="post">
{% 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 Announcements">
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Save Changes to Announcement" />
</form>
</div>
{% endblock %}
from .forms import AddAnnouncement
from .forms import AnnouncementForm
from .models import Announcement, Reaction
from django.views.generic import ListView, DetailView, CreateView, UpdateView
from django.db.models import Sum
......@@ -30,15 +30,15 @@ class AnnouncementDetailView(DetailView):
class AnnouncementCreateView(CreateView):
model = Announcement
form_class = AddAnnouncement
form_class = AnnouncementForm
template_name = "announcements/announcement-add.html"
def get_success_url(self):
return reverse("announcements:announcement_details", args=(self.object.pk,))
return reverse("announcements:announcement_details", kwargs={"pk": self.object.pk})
class AnnouncementEditView(UpdateView):
model = Announcement
form_class = AddAnnouncement
form_class = AnnouncementForm
template_name = "announcements/announcement-edit.html"
def get_success_url(self):
......
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