Commit 00d6d9f0 authored by Deokhyun Lee's avatar Deokhyun Lee

Merge branch 'announcements_wip'

parents 36d2898e 3b5393e1
......@@ -3,7 +3,7 @@ Section C
Group Members:
Damalerio, Adrian Lance T.
[Insert Name]
Syquia, Luis Augusto A.
[Insert Name]
[Insert Name]
[Insert Name]
......@@ -11,6 +11,7 @@ Damalerio, Adrian Lance T.
Midterm Proj: Widget v1
App Assignments:
Announcement Board - Syquia
Date of Submission:
......@@ -19,3 +20,4 @@ Date of Submission:
[References]
(sgd) Adrian Lance T. Damalerio
(sgd) Luis Augusto A. Syquia
from django.contrib import admin
from .models import Announcement, Reaction
# Register your models here.
class ReactionInline(admin.TabularInline):
model = Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
search_fields = ('title', 'author',)
list_display = ('title', 'body', 'author', 'pub_datetime',)
list_filter = ('title', 'author', 'pub_datetime',)
inlines = [ReactionInline,]
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
search_fields = ('name', 'announcement',)
list_display = ('name', 'tally', 'announcement',)
list_filter = ('name', 'tally',)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
# Generated by Django 3.2 on 2023-03-05 14:28
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dashboard', '0002_alter_widgetuser_department'),
]
operations = [
migrations.CreateModel(
name='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('body', models.TextField(max_length=420)),
('pub_datetime', models.DateTimeField(auto_now_add=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], max_length=100)),
('tally', models.IntegerField(default=1)),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcement_board.announcement')),
],
),
]
# Generated by Django 3.2 on 2023-03-05 15:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcement_board', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='reaction',
name='name',
field=models.CharField(max_length=100),
),
migrations.AlterField(
model_name='reaction',
name='tally',
field=models.IntegerField(default=0),
),
]
from django.db import models
from dashboard.models import WidgetUser
# Create your models here.
class Announcement(models.Model):
title = models.CharField(max_length=50)
body = models.TextField(max_length=420)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
class Reaction(models.Model):
name = models.CharField(max_length=100)
tally = models.IntegerField(default=0)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
def __str__(self):
return self.name
#announcements/urls.py
from django.urls import path
from .import views
urlpatterns = [
path("", views.announcement_boardIndex, name = "announcement_boardIndex")
]
app_name = "announcement_board"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
def announcement_boardIndex(request):
announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
announcement_board_output = "Widget’s Announcement Board <br><br> Announcements: <br>"
for announcement in announcements:
datetime = announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p")
announcement_board_output += (announcement.title + " by " + announcement.author.first_name +
" " + announcement.author.last_name + " published " + datetime +
": <br>" + announcement.body + "<br>"
)
like_tally = 0
love_tally = 0
angry_tally = 0
for reaction in reactions:
if reaction.announcement.title == announcement.title:
if reaction.name == "Like":
like_tally = reaction.tally
elif reaction.name == "Love":
love_tally = reaction.tally
elif reaction.name == "Angry":
angry_tally = reaction.tally
announcement_board_output = (announcement_board_output + "Like: " + str(like_tally) + "<br>Love: " +
str(love_tally) + "<br>Angry: " + str(angry_tally) + "<br><br>")
return HttpResponse(announcement_board_output)
\ No newline at end of file
# Create your views here.
......@@ -21,5 +21,6 @@ urlpatterns = [
path("dashboard/", include("dashboard.urls", namespace="dashboard")),
path("assignments/", include("assignments.urls")),
path("forum/", include("forum.urls")),
path("calendar/", include("calendar_app.urls"))
path("calendar/", include("calendar_app.urls")),
path("announcements/", include("announcement_board.urls", namespace="announcement_board")),
]
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