Commit 357ed8d4 authored by Mary Adelaide A. Salto's avatar Mary Adelaide A. Salto
parents 5e2aaeb2 56331e7a
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('title', 'author', 'pub_datetime')
search_fields = ('title', 'author',)
list_filter = ['author', 'pub_datetime']
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = ('name', 'tally', 'announcement')
search_fields = ('name',)
list_filter = ['name']
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
from django.apps import AppConfig
class AnnouncementBoardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'announcement_board'
# Generated by Django 4.1.7 on 2023-03-04 08:24
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
]
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.CharField(max_length=500)),
('author', models.CharField(max_length=100)),
('pub_datetime', models.DateTimeField(default=django.utils.timezone.now, null=True, verbose_name='date published')),
],
),
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')], default='Like', max_length=10)),
('tally', models.IntegerField(default=0)),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcement_board.announcement')),
],
),
]
# Generated by Django 4.1.7 on 2023-03-04 09:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcement_board', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='body',
field=models.TextField(max_length=10000),
),
]
from django.db import models
from django.utils import timezone
from dashboard.models import WidgetUser
Like = 'Like'
Love = 'Love'
Angry = 'Angry'
REACTIONS = ((Like, 'Like'),
(Love, 'Love'),
(Angry, 'Angry'))
class Announcement(models.Model):
title = models.CharField(max_length=100)
body = models.TextField(max_length=10000)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField(default=timezone.now, null=True, blank=True)
def __str__(self):
return self.title
class Reaction(models.Model):
name = models.CharField(max_length=10, choices=REACTIONS, default=Like)
tally = models.IntegerField(default = 0)
announcement = models.ForeignKey(Announcement, on_delete = models.CASCADE)
def __str__(self):
return self.name
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
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 index(request):
announcement_view = "Widget's Announcement Board <br/>"
announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
for a in announcements:
like_tally=0
love_tally=0
angry_tally=0
for r in reactions:
if r.name=="Like" and r.announcement==a:
like_tally+=r.tally
elif r.name=="Love" and r.announcement==a:
love_tally+=r.tally
elif r.name=="Angry" and r.announcement==a:
angry_tally+=r.tally
announcement_view += "<br/> {} by {} {} published {}: <br/> {} <br/> Like: {} <br/> Love: {} <br/> Angry: {} <br/>".\
format(a.title,
a.author.first_name,
a.author.last_name,
a.pub_datetime.strftime('%m/%d/%Y, %H:%M %p'),
a.body,
like_tally,
love_tally,
angry_tally)
return HttpResponse(announcement_view)
\ No newline at end of file
......@@ -42,6 +42,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'dashboard'
'announcement_board',
]
MIDDLEWARE = [
......
......@@ -15,8 +15,10 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import include, path
from django.urls import path, include
urlpatterns = [
path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('admin/', admin.site.urls),
]
\ No newline at end of file
path('announcement_board/', 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