Applied migrations and updated tally field and views.py

parent 4558cfc7
# Generated by Django 4.0.3 on 2022-04-06 07:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0007_remove_reaction_tally_reaction_id'),
]
operations = [
migrations.AddField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=1),
),
]
...@@ -18,11 +18,14 @@ class Reaction(models.Model): ...@@ -18,11 +18,14 @@ class Reaction(models.Model):
max_length=5, max_length=5,
choices=REACTION_CHOICES, choices=REACTION_CHOICES,
) )
tally = models.IntegerField(default=1) tally = models.IntegerField(default=0)
def __str__(self): def __str__(self):
return '{}'.format(self.reaction_name) return '{}'.format(self.reaction_name)
def get_tally(self):
return '{}'.format(self.tally)
class Announcement(models.Model): class Announcement(models.Model):
announcement_title = models.CharField(max_length=100) announcement_title = models.CharField(max_length=100)
......
...@@ -6,7 +6,6 @@ from .models import Announcement, Reaction ...@@ -6,7 +6,6 @@ from .models import Announcement, Reaction
def index(request): def index(request):
return HttpResponse('This is the Announcement Board!') return HttpResponse('This is the Announcement Board!')
def announcements(request): def announcements(request):
all_announcements = models.Announcement.objects.all() all_announcements = models.Announcement.objects.all()
all_reactions = models.Reaction.objects.all() all_reactions = models.Reaction.objects.all()
...@@ -19,9 +18,9 @@ def announcements(request): ...@@ -19,9 +18,9 @@ def announcements(request):
date = str(i.pub_date) date = str(i.pub_date)
last_name = i.author.last_name last_name = i.author.last_name
first_name = i.author.first_name first_name = i.author.first_name
like_tally = Reaction.objects.filter(reaction_name='Like', announcement=i) like_tally = str(Reaction.objects.get(reaction_name='Like', announcement=i).get_tally())
love_tally = Reaction.objects.filter(reaction_name='Love', announcement=i) love_tally = str(Reaction.objects.get(reaction_name='Love', announcement=i).get_tally())
angry_tally = Reaction.objects.filter(reaction_name='Angry', announcement=i) angry_tally = str(Reaction.objects.get(reaction_name='Angry', announcement=i).get_tally())
output = (title+' by '+first_name+' '+last_name+' dated '+date+':<br>' output = (title+' by '+first_name+' '+last_name+' dated '+date+':<br>'
+body+'<br>' +body+'<br>'
......
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