Commit bbab1cb3 authored by Jayson Lim's avatar Jayson Lim

Updated model class and its attributes, also updated the implementation of view

parent 7cc4c2cc
from django.db import models
from dashboard.models import WidgetUser
class Announcement(models.Model):
title = models.CharField(max_length=250, default="")
body = models.TextField(null=True, blank=True)
......@@ -8,9 +9,9 @@ class Announcement(models.Model):
WidgetUser,
null=True,
default=True,
on_delete=models.SET_DEFAULT,
on_delete=models.CASCADE,
related_name='announcements',
)
pub_datetime = models.DateTimeField(auto_now_add=True)
def __str__(self):
......@@ -20,14 +21,18 @@ class Announcement(models.Model):
return self.pub_datetime.strftime('%m/%d/%Y %I:%M %p')
class Reaction(models.Model):
name = models.CharField(max_length=5, default='')
name = models.CharField(max_length=5, choices=[('Like', 'Like'),
('Love', 'Love'),
('Angry', 'Angry')], default='Like')
tally = models.PositiveIntegerField(default=0)
annoucement = models.ForeignKey(
Announcement,
null=True,
default=True,
on_delete=models.SET_DEFAULT
on_delete=models.CASCADE,
related_name='reactions'
)
def __str__(self):
return self.name
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement
from .models import Reaction
from dashboard.models import WidgetUser
def index(request):
......@@ -13,26 +13,19 @@ def index(request):
body = "<h2>Announcements:</h2>"
announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
for i in range(0, len(announcements), 1):
announcement = announcements[i]
for x in Announcement.objects.all():
reaction = x.reactions.all()
body += "<p style='border: 2px solid gray;\
border-radius:5px;\
padding:20px 30px;'>\
{} by {} published {}:\
<br>\
{}\
</p>".format(announcement.title, announcement.author,
announcement.format_pub_datetime(), announcement.body)
for j in range(i * 3, (i + 1) * 3):
if j >= len(reactions):
break
reaction = reactions[j]
</p>".format(x.title, x.author,
x.format_pub_datetime(), x.body)
for y in reaction:
body += "<p>{}: {}\
</p>".format(reaction.name, reaction.tally)
</p>".format(y.name, y.tally)
body += '<p>&nbsp;</p>'
......
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