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