Commit 9ced99c7 authored by Junho Park's avatar Junho Park

fix: fixed announcement and reaction models, populated new fields

parent b284f9b5
# Generated by Django 3.2.12 on 2022-04-07 19:42
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('announcements', '0003_auto_20220407_1707'),
]
operations = [
migrations.RemoveField(
model_name='announcement',
name='reaction',
),
migrations.AddField(
model_name='reaction',
name='announcement',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement'),
),
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=0),
),
]
......@@ -2,6 +2,21 @@ from django.db import models
from homepage.models import WidgetUser
# Create your models here.
class Announcement(models.Model):
announcement_title = models.CharField(max_length=100)
announcement_body = models.CharField(max_length=1000)
pub_date = models.DateTimeField('date published')
author = models.ForeignKey(
'homepage.WidgetUser',
on_delete=models.CASCADE,
default=None,
null=True
)
def __str__(self):
return self.announcement_title
class Reaction(models.Model):
LOVE = 'Love'
LIKE = 'Like'
......@@ -17,27 +32,14 @@ class Reaction(models.Model):
default=None,
)
tally = models.IntegerField()
def __str__(self):
return self.reaction_name
class Announcement(models.Model):
announcement_title = models.CharField(max_length=100)
announcement_body = models.CharField(max_length=1000)
pub_date = models.DateTimeField('date published')
author = models.ForeignKey(
'homepage.WidgetUser',
announcement = models.ForeignKey(
'Announcement',
on_delete=models.CASCADE,
default=None,
null=True
)
reaction = models.ForeignKey(
'Reaction',
on_delete=models.CASCADE,
default=None,
null=True
null=True,
)
tally = models.IntegerField(default=0)
def __str__(self):
return self.announcement_title
return self.reaction_name
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1> ANNOUNCEMENTS: </h1>
{% for announcement in announcement_entries %}
<p>
{{announcement.announcement_title}} by {{announcement.author.first_name}} {{announcement.author.last_name}} dated {{announcement.pub_date}}:<br>
{{announcement.announcement_body}}<br>
Like: {{announcement.reaction.filter(reaction_name__exact="Like").tally}}<br>
Love: {{announcement.reaction.filter(reaction_name__exact="Love").tally}}<br>
Angry: {{announcement.reaction.filter(reaction_name__exact="Angry").tally}}
</p>
{% endfor %}
</body>
</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