The Models, Admin, Urls, Etc. have been coded for Announcement App.

parent c267ec90
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
from django.apps import AppConfig
class AnnouncementConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'announcement'
# Generated by Django 4.1.7 on 2023-03-07 03:33
from django.db import migrations, models
import django.db.models.deletion
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=100, null=True)),
('body', models.TextField(null=True)),
('author', models.CharField(max_length=100, null=True)),
('pub_datetime', models.DateTimeField(null=True)),
],
),
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'), ('Heart', 'Heart'), ('Angry', 'Angry')], default='Like', max_length=10)),
('tally', models.IntegerField(null=True)),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcement.announcement')),
],
),
]
from django.db import models
# Create your models here.
class Announcement(models.Model):
title = models.CharField(max_length=100, null = True)
body = models.TextField(null = True)
author = models.CharField(max_length=100, null = True)
pub_datetime = models.DateTimeField(null = True)
def __str__(self):
return '{} by {} published {}: {}'.format(self.title, self.author, self.pub_datetime, self.body)
class Reaction(models.Model):
reaction_list = [("Like", "Like"), ("Heart", "Heart"), ("Angry", "Angry")]
name = models.CharField(max_length=10, choices = reaction_list, default = "Like")
tally = models.IntegerField(null = True)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
def __str__(self):
return '{}: {}'.format(self.name, self.tally)
from django.test import TestCase
# Create your tests here.
from django.contrib import admin
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "announcement"
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
def index(request):
page_content ="""<H1>Widget's Announcement Board</H1?"""
for announcement in Announcement.objects.all():
newAnnouncementDateTime = announcement.pub_datetime.strftime("%m-%d-%Y %I:%M %p")
page_content += """<br> <br>
{} by {} published {}:<br>
{}<br>""".format(announcement.title, announcement.author, newAnnouncementDateTime, announcement.body)
for reaction in Reaction.objects.all():
if reaction.announcement == announcement:
page_content += """<br>{}: {}
""".format(reaction.name, reaction.tally)
return HttpResponse(page_content)
No preview for this file type
......@@ -42,6 +42,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'announcement',
'assignments',
'dashboard',
'forum',
......
......@@ -2,6 +2,7 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('announcement/', include('announcement.urls', namespace="announcement")),
path('widget_calendar/', include('widget_calendar.urls', namespace="widget_calendar")),
path('assignments/', include('assignments.urls', namespace="assignments")),
path('dashboard/', include('dashboard.urls', namespace="dashboard")),
......
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