Commit e99251dc authored by mantlei's avatar mantlei

Fully Completed and Functional Announcements Board with populated models

parent 76cad784
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('title', 'body', 'author',)
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = ('name', 'tally', 'announcement',)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
from django.apps import AppConfig
class AnnouncementsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'announcements'
# Generated by Django 4.1.7 on 2023-03-05 14:22
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dashboard', '0001_initial'),
]
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=255, null=True)),
('body', models.TextField(null=True)),
('pub_datetime', models.DateTimeField(null=True)),
('author', models.ForeignKey(null=True, 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(max_length=255, null=True)),
('tally', models.IntegerField(null=True)),
('announcement', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
]
from django.db import models
from dashboard.models import WidgetUser
class Announcement(models.Model):
title = models.CharField(max_length=255, null=True)
body = models.TextField(null=True)
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE, null=True)
pub_datetime = models.DateTimeField(null=True)
def __str__(self):
return f"{self.title}"
class Reaction(models.Model):
name = models.CharField(max_length=255, null=True)
tally = models.IntegerField(null=True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, null=True)
def __str__(self):
return f"{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 = "announcements"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
import datetime
def index(request):
overall_board = "<html><title>Assignments</title><body>" \
"<h1> Widget's Announcement Board</h1>"
for announcement in Announcement.objects.all():
overall_board += "<p><b>Announcements:<br>"
overall_board += "%s by " %announcement.title
overall_board += "%s " %announcement.author.first_name
overall_board += "%s published " %announcement.author.last_name
overall_board += "%s, " %announcement.pub_datetime.date().strftime("%m/%d/%Y")
overall_board += "%s<br>" %announcement.pub_datetime.time().strftime("%I:%M %p")
overall_board += "%s<br>" %announcement.body
for reaction in Reaction.objects.all():
if reaction.announcement == announcement:
overall_board += "%s: " %reaction.name
overall_board += "%i<br>" %reaction.tally
overall_board += "</body></html>"
return HttpResponse(overall_board)
\ No newline at end of file
No preview for this file type
...@@ -38,6 +38,7 @@ INSTALLED_APPS = [ ...@@ -38,6 +38,7 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'dashboard', 'dashboard',
'announcements',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -19,4 +19,5 @@ from django.urls import include, path ...@@ -19,4 +19,5 @@ from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('dashboard/', include('dashboard.urls', namespace="dashboard")), path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('announcements/', include('announcements.urls', namespace="announcements")),
] ]
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