Commit 13e880fe authored by Jiuvi Anne Hu's avatar Jiuvi Anne Hu

Changed variable names and fixed templates.

parent 619afd5f
# Generated by Django 3.2 on 2023-05-13 14:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='react', to='announcements.announcement'),
),
]
...@@ -19,6 +19,6 @@ class Reaction(models.Model): ...@@ -19,6 +19,6 @@ class Reaction(models.Model):
name = models.CharField(max_length=5, default=LIKE, null=True, blank=True) name = models.CharField(max_length=5, default=LIKE, null=True, blank=True)
tally = models.IntegerField(default=0 ,null=True, blank=True) tally = models.IntegerField(default=0 ,null=True, blank=True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True) announcement = models.ForeignKey(Announcement, related_name="react", on_delete=models.CASCADE, null=True)
# Create your models here. # Create your models here.
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
<title>Add Announcement</title> <title>Add Announcement</title>
<h1>Add a new announcement:</h1> <h1>Add a new announcement:</h1>
<form action="/" method="post"> <form action="" method=POST>
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" value="Save Changes to Announcement"> <input type="submit" value="Add Announcement">
</form> </form>
{% endblock content %} {% endblock content %}
\ No newline at end of file
...@@ -3,17 +3,18 @@ ...@@ -3,17 +3,18 @@
{% block content %} {% block content %}
<title>{{announcement.title}}</title> <title>{{ announce.title }}</title>
<h1>{{announcement.title}}</h1> <h1>{{ announce.title }}</h1>
<h2>by</h2> <h2>by {{ announce.author.first_name }} {{ announce.author.last_name }}</h2>
<p>{{ announce.pub_datetime|date:'m/d/Y, h:i A' }}</p>
<p>{{ announcement.body }}</p><br> <p>{{ announce.body }}</p>
<p> <p>
{% for reaction in reaction.model.all %} {% for react in announce.react.all %}
{{ reaction.name }}: {{ reaction.tally }}<br> {{ react.name }}: {{ react.tally }}<br>
{% endfor %} {% endfor %}
</p> </p>
<a href = "announcements/<int:pk>/edit/"><button value="">Edit Announcement</button></a> <a href = "/announcements/{{ announce.pk }}/edit/"><button value="">Edit Announcement</button></a>
{% endblock content %} {% endblock content %}
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<title>Edit Announcement</title> <title>Edit Announcement</title>
<h1>Edit announcement:</h1> <h1>Edit announcement:</h1>
<form action="/" method=POST> <form action="" method=POST>
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" value="Save Changes to Announcement"> <input type="submit" value="Save Changes to Announcement">
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
<h1>Welcome to Widget's Announcement Board!</h1> <h1>Welcome to Widget's Announcement Board!</h1>
<h3>Announcements:</h3> <h3>Announcements:</h3>
{% for announcement in announcements %} {% for announce in announcement %}
<a href = "announcements/{{ announcedetails.pk }}/details/">{{ announcement.title }} by {{ announcement.author.first_name }} {{ announcement.author.last_name }}</a><br> <a href = "{{ announce.pk }}/details/">{{ announce.title }} by {{ announce.author.first_name }} {{ announce.author.last_name }}</a><br>
{% endfor %} <br> {% endfor %} <br>
<a href="add/"><button value="click here">Add Announcement</button></a><br><br> <a href="add/"><button value="click here">Add Announcement</button></a><br><br>
......
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView from django.views.generic.edit import CreateView, UpdateView
from django.urls import reverse
from .models import Announcement, Reaction from .models import Announcement, Reaction
import pytz import pytz
from django.utils import timezone from django.utils import timezone
...@@ -12,7 +13,6 @@ def convert_to_localtime(utctime): ...@@ -12,7 +13,6 @@ def convert_to_localtime(utctime):
localtz = utc.astimezone(timezone.get_current_timezone()) localtz = utc.astimezone(timezone.get_current_timezone())
return localtz.strftime(format) return localtz.strftime(format)
def index(request): def index(request):
announcement = Announcement.objects.all().order_by('-pub_datetime') announcement = Announcement.objects.all().order_by('-pub_datetime')
context = { context = {
...@@ -25,11 +25,11 @@ class AnnouncementDetailView(DetailView): ...@@ -25,11 +25,11 @@ class AnnouncementDetailView(DetailView):
model = Announcement model = Announcement
template_name = 'announcements/announcement-details.html' template_name = 'announcements/announcement-details.html'
queryset = Announcement.objects.all() queryset = Announcement.objects.all()
context_object_name = 'annoucedetails' context_object_name = 'announce'
class AnnouncementAddView(CreateView): class AnnouncementAddView(CreateView):
model = Announcement model = Announcement
fields = '__all__' fields = ['title', 'body', 'author']
template_name = 'announcements/announcement-add.html' template_name = 'announcements/announcement-add.html'
def get_success_url(self): def get_success_url(self):
...@@ -39,6 +39,7 @@ class AnnouncementAddView(CreateView): ...@@ -39,6 +39,7 @@ class AnnouncementAddView(CreateView):
class AnnouncementEditView(UpdateView): class AnnouncementEditView(UpdateView):
model = Announcement model = Announcement
template_name = 'announcements/announcement-edit.html' template_name = 'announcements/announcement-edit.html'
fields = ['title', 'body', 'author']
def get_success_url(self): def get_success_url(self):
return reverse('announcement:announcementdetailview', kwargs={'pk': self.object.id}, return reverse('announcement:announcementdetailview', kwargs={'pk': self.object.id},
......
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