Commit a90b30d4 authored by Colleen's avatar Colleen

Announcement Board app created and modified

parent 6a0dc18f
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('title','body','author','pub_datetime',)
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 AnnouncementBoardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Announcement_Board'
# Generated by Django 4.1.6 on 2023-03-05 04:32
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)),
('body', models.CharField(max_length=2000)),
('author', models.CharField(max_length=50)),
('pub_datetime', models.CharField(max_length=700)),
],
),
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()),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Announcement_Board.announcement')),
],
),
]
from django.db import models
class Announcement(models.Model):
title = models.CharField(max_length=100)
body = models.CharField(max_length=2000)
author = models.CharField(max_length=50)
pub_datetime = models.CharField(max_length=700)
class Reaction(models.Model):
name_choices = (
('like','like'),
('love','love'),
('angry','angry'),
)
name = models.CharField(max_length=100, choices=name_choices)
tally = models.IntegerField()
announcement = models.ForeignKey(Announcement, on_delete = models.CASCADE)
\ 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 = "AnnouncementBoard"
\ No newline at end of file
from django.shortcuts import render
from django.shortcuts import HttpResponse
from .models import Announcement, Reaction
def index(request):
return_string = '<ul>'
for reaction in Reaction.objects.all():
return_string += '<li>{} {} {}: <br> {} <br> {} {} {} </li>'.format(
reaction.announcement.title, reaction.announcement.author, reaction.announcement.pub_datetime, reaction.announcement, reaction.tally, reaction.tally, reaction.tally
)
return_string += '</ul>'
html_string = '<html><head>Widget’s Announcement Board<br> <br>Announcements:</head><body>{}</body><html>'.format(return_string)
return HttpResponse(html_string)
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