Commit a418f376 authored by Maso Crisostomo's avatar Maso Crisostomo

Update Announcements to have authors and reactions

parent 8c689245
# Generated by Django 3.2.12 on 2022-04-05 05:33
# Generated by Django 3.2.12 on 2022-03-22 08:20
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
......@@ -9,7 +8,6 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('homepage', '0001_initial'),
]
operations = [
......@@ -20,16 +18,6 @@ class Migration(migrations.Migration):
('announcement_title', models.CharField(max_length=70)),
('announcement_body', models.CharField(max_length=1000)),
('pub_date', models.DateTimeField(auto_now_add=True)),
('author', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reaction_name', models.CharField(max_length=15)),
('tally', models.IntegerField(default=0)),
('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
]
# Generated by Django 4.0.3 on 2022-04-05 10:48
# Generated by Django 3.2.12 on 2022-04-05 11:17
from django.db import migrations, models
import django.db.models.deletion
......@@ -8,7 +8,7 @@ class Migration(migrations.Migration):
dependencies = [
('homepage', '0004_widgetuser_department'),
('announcements', '0002_remove_announcement_author'),
('announcements', '0001_initial'),
]
operations = [
......@@ -17,4 +17,13 @@ class Migration(migrations.Migration):
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reaction_name', models.CharField(max_length=15)),
('tally', models.IntegerField(default=0)),
('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
]
# Generated by Django 4.0.3 on 2022-04-05 10:47
# Generated by Django 3.2.12 on 2022-04-05 12:37
from django.db import migrations
......@@ -6,12 +6,13 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('announcements', '0001_initial'),
('announcements', '0002_auto_20220405_1917'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='author',
migrations.RenameField(
model_name='reaction',
old_name='article',
new_name='announcement',
),
]
......@@ -14,9 +14,9 @@ class Announcement(models.Model):
return self.announcement_title
class Reaction(models.Model):
article = models.ForeignKey(Announcement, on_delete=models.CASCADE)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
reaction_name = models.CharField(max_length=15)
tally = models.IntegerField(default=0)
def __str__(self):
return self.reaction_name
\ No newline at end of file
return self.reaction_name
from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here.
def index(request):
return HttpResponse("This is the Announcement Board!")
\ No newline at end of file
content = 'ANNOUNCEMENTS:<br/>'
announcements = Announcement.objects.all()
reacts = Reaction.objects.all()
for i in announcements:
announcement_date = i.pub_date.date().strftime("%m/%d/%Y")
content += f'{i.announcement_title} by {i.author.first_name} {i.author.last_name} dated {announcement_date}:<br/>{i.announcement_body}<br/>'
for j in reacts:
if j.announcement == i:
content += f'{j.reaction_name}: {j.tally}<br/>'
content += '<br/>'
return HttpResponse(content)
# Display all available Announcements and their respective Reactions in the format
# <announcement_title> by <author’s first_name> <author’s last_name> dated <pub_date>:
# announcement_body
# Like: <count>
# Love: <count>
# Angry: <count>
# with the heading “ANNOUNCEMENTS: ”. An empty line separates the announcements
# from each other.
# ■ Example:
# ANNOUNCEMENTS:
# No Synch Session by Alice Wonderland dated 03/16/2022:
# There will be no synch session next week.
# Like: 3
# Love: 5
# Angry: 0
# Project Deadline by Little Luly dated 03/16/2022
# Deadline for the project is next month.
# Like: 4
# Love: 6
# Angry: 3
\ No newline at end of file
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