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 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
# Create your models here. # Create your models here.
...@@ -17,6 +18,9 @@ class Announcement(models.Model): ...@@ -17,6 +18,9 @@ class Announcement(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('announcements:announcement-details', kwargs={'pk': self.pk}) return reverse('announcements:announcement-details', kwargs={'pk': self.pk})
def save(self):
self.announcement_pub_datetime = timezone.now()
reaction_choices = ( reaction_choices = (
('Like', 'Like'), ('Like', 'Like'),
......
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %}{{ announcement.announcement_title }}{% endblock %} {% block title %}{{ announcement.announcement_title }}{% endblock %}
{% block content %} {% block content %}
<h1>{{ announcement.announcement_title }}</h1> <h1>{{ announcement.announcement_title }} <br>
<h2> by {{ announcement.announcement_author.first_name }} by {{ announcement.announcement_author.first_name }}
{{ announcement.announcement_author.last_name }} {{ announcement.announcement_author.last_name }}
</h2> </h1>
{{ announcement.announcement_pub_datetime }} <br> {{ announcement.announcement_pub_datetime }} <br>
{{ announcement.announcement_body }}<br> {{ announcement.announcement_body }} <br>
{{ reaction.reaction_name }} {% for reaction in reactions %}
<p>{{ reaction.reaction_name }}: {{ reaction.reaction_tally }}</p>
{% endfor %} <br>
<a><button>Edit Announcement</button></a> <a><button>Edit Announcement</button></a>
{% endblock %} {% endblock %}
\ No newline at end of file
<!DOCTYPE html> {% extends 'base.html' %}
<html lang="en"> {% block title %} Edit Announcement {% endblock %}
<head> {% block content %}
<meta charset="UTF-8"> <h1> Edit announcement:</h1>
<title>Title</title> <form method="POST">
</head> {% csrf_token %}
<body> {{ form.as_p }}
<input type="Submit" value="Save Changes">
</body> </form>
</html> {% endblock %}
\ No newline at end of file \ No newline at end of file
...@@ -16,18 +16,25 @@ def Announcements(request): ...@@ -16,18 +16,25 @@ def Announcements(request):
return render(request, 'announcements/announcements.html', context) return render(request, 'announcements/announcements.html', context)
class AnnouncementsDetailsView(DetailView): class AnnouncementsDetailsView(DetailView):
model = Announcement 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): class AnnouncementsCreateView(CreateView):
model = Announcement model = Announcement
fields = 'announcement_title', 'announcement_body', 'announcement_author' fields = 'announcement_title', 'announcement_body', 'announcement_author'
template_name = 'announcements/announcement-add.html' template_name = 'announcements/announcement-add.html'
class AnnouncementsEditView(UpdateView): class AnnouncementsEditView(UpdateView):
model = Announcement model = Announcement
fields = 'announcement_title', 'announcement_body', 'announcement_author'
template_name = 'announcements/announcement-edit.html' 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