Commit 5bd8ffcd authored by Junho Park's avatar Junho Park

feat: update view of Announcements app

parent 9ced99c7
No preview for this file type
# Generated by Django 3.2.12 on 2022-04-08 02:38
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('announcements', '0004_auto_20220407_1942'),
]
operations = [
migrations.RemoveField(
model_name='reaction',
name='tally',
),
]
# Generated by Django 3.2.12 on 2022-04-08 03:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0005_remove_reaction_tally'),
]
operations = [
migrations.AddField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=0),
),
]
......@@ -43,3 +43,5 @@ class Reaction(models.Model):
def __str__(self):
return self.reaction_name
def count(self):
return self.tally
<!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>
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here.
def index(request):
return HttpResponse('This is the Announcement Board!')
announcement = Announcement.objects.all()
html = '<html><body><h3>ANNOUNCEMENT POSTS:</h3>'
for a in announcement:
html += "{} by {} {} dated {}:<br>{}<br>".format(
a.announcement_title,
a.author.first_name,
a.author.last_name,
a.pub_date,
a.announcement_body,
)
reaction = Reaction.objects.filter(announcement=a.id)
html += "Like: {}<br>Love: {}<br>Angry: {}".format(
reaction.filter(reaction_name__exact="Like").count,
reaction.filter(reaction_name__exact="Love").count,
reaction.filter(reaction_name__exact="Angry").count,
)
html += '<br>'
html += '</body></html>'
return HttpResponse(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