Commit 80ce3337 authored by Emilio Gentolia's avatar Emilio Gentolia

Merge branch 'gentolia/announcement_board'

parents 483b128b 7a593964
from django.contrib import admin
from .models import Announcement
from .models import Announcement, Reaction
#Announcement admin panel
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, AnnouncementAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-02 16:00
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
('announcement_board', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='announcement',
name='author',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateTimeField(verbose_name='date published'),
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reaction_name', models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default='Like', max_length=5)),
('tally', models.IntegerField(default=0)),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcement_board.announcement')),
],
),
]
# Generated by Django 4.0.3 on 2022-04-03 08:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcement_board', '0002_announcement_author_alter_announcement_pub_date_and_more'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='pub_date',
field=models.DateField(verbose_name='date published'),
),
]
from django.db import models
from homepage.models import WidgetUser
class Announcement(models.Model):
announcement_title = models.CharField(max_length=120)
announcement_body = models.TextField(blank=True)
pub_date = models.DateField(auto_now_add=True)
pub_date = models.DateField("date published")
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
def __str__(self):
return self.announcement_title
class Reaction(models.Model):
LIKE = "Like"
LOVE = "Love"
ANGRY = "Angry"
REACTION_CHOICES = [
(LIKE, "Like"),
(LOVE, "Love"),
(ANGRY, "Angry")
]
reaction_name = models.CharField(
max_length=5,
choices=REACTION_CHOICES,
default=LIKE
)
tally = models.IntegerField(default=0)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
def __str__(self):
return self.reaction_name
\ No newline at end of file
from django.http import HttpResponse
from .models import Announcement, Reaction
# View for announcements page.
def index(request):
return HttpResponse("This is the Announcement Board!")
return HttpResponse(display_announcementboard(Announcement.objects.all(), Reaction.objects.all()))
def display_announcementboard(announcement_data, reaction_data):
display_output = "ANNOUNCEMENTS: <br>"
for object in announcement_data:
announcement_title = object.announcement_title
first_name = object.author.first_name
last_name = object.author.last_name
pub_date = str(object.pub_date)
announcement_body = object.announcement_body
like_count = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Like").first().tally
love_count = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Love").first().tally
angry_count = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Angry").first().tally
display_output += f'''
{announcement_title} by {first_name} {last_name} dated {pub_date}:<br>
{announcement_body}<br>
Like: {like_count}<br>
Love: {love_count}<br>
Angry: {angry_count}<br>
<br>
'''
return display_output
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