Commit cbf7cd07 authored by Ross Batacan's avatar Ross Batacan

Created announcements/edit URL. Issues: DateTime of publish is not saved as a...

Created announcements/edit URL. Issues: DateTime of publish is not saved as a new announcement is made
parent 899647f4
from django.db import models
from dashboard.models import WidgetUser
from django.urls import reverse
from django.utils import timezone
# Create your models here.
......@@ -17,6 +18,9 @@ class Announcement(models.Model):
def get_absolute_url(self):
return reverse('announcements:announcement-details', kwargs={'pk': self.pk})
def save(self):
self.announcement_pub_datetime = timezone.now()
reaction_choices = (
('Like', 'Like'),
......
{% extends 'base.html' %}
{% block title %}{{ announcement.announcement_title }}{% endblock %}
{% block content %}
<h1>{{ announcement.announcement_title }}</h1>
<h2> by {{ announcement.announcement_author.first_name }}
<h1>{{ announcement.announcement_title }} <br>
by {{ announcement.announcement_author.first_name }}
{{ announcement.announcement_author.last_name }}
</h2>
</h1>
{{ announcement.announcement_pub_datetime }} <br>
{{ announcement.announcement_body }}<br>
{{ reaction.reaction_name }}
{{ announcement.announcement_body }} <br>
{% for reaction in reactions %}
<p>{{ reaction.reaction_name }}: {{ reaction.reaction_tally }}</p>
{% endfor %} <br>
<a><button>Edit Announcement</button></a>
{% endblock %}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %} Edit Announcement {% endblock %}
{% block content %}
<h1> Edit announcement:</h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
......@@ -16,18 +16,25 @@ def Announcements(request):
return render(request, 'announcements/announcements.html', context)
class AnnouncementsDetailsView(DetailView):
model = Announcement
template_name = 'announcements/announcement-details.html'
template_name = 'announcements/announcement-details.html'\
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['reactions'] = Reaction.objects.filter(reaction_announcement=self.object)
return context
class AnnouncementsCreateView(CreateView):
model = Announcement
fields = 'announcement_title', 'announcement_body', 'announcement_author'
template_name = 'announcements/announcement-add.html'
class AnnouncementsEditView(UpdateView):
model = Announcement
fields = 'announcement_title', 'announcement_body', 'announcement_author'
template_name = 'announcements/announcement-edit.html'
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