Commit de9e295a authored by Anthony Bicomong's avatar Anthony Bicomong

Added announcements app

parent 824b9b44
from django.contrib import admin
# Register your models here.
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('title', 'body', 'author', 'pub_datetime')
search_fields = ('title', 'body', 'author', 'pub_datetime')
list_filter = ('title', 'body', 'author', 'pub_datetime')
class AnnonuncementInline(admin.TabularInline):
model = Announcement
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = ('name', 'tally', 'announcement')
search_fields = ('name', 'tally', 'announcement')
list_filter = ('name', 'tally', 'announcement')
class ReactionInline(admin.TabularInline):
model = Reaction
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
# Generated by Django 3.2 on 2023-03-02 06:17
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=50)),
('body', models.CharField(max_length=700)),
('author', models.CharField(max_length=200)),
('pub_datetime', models.DateTimeField()),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('tally', models.IntegerField()),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
]
from django.db import models
from django.urls import reverse
# Create your models here.
class Announcement(models.Model):
title = models.CharField(max_length=50)
body = models.CharField(max_length=700)
#author = models.ForeignKey("dashboard.WidgetUser", on_delete=models.CASCADE)
author = models.CharField(max_length=200)
pub_datetime = models.DateTimeField()
def __str__(self):
return self.title
class Reaction(models.Model):
name = models.CharField(max_length=50)
tally = models.IntegerField()
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
def __str__(self):
return self.name
\ No newline at end of file
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "announcements"
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
def index(request):
all_announcements = Announcement.objects.all()
all_reactions = Reaction.objects.all()
response = "Big Django Energy - Announcement Board<br><br>Announcements:<br>"
for announcement in all_announcements:
announcementpubdate = announcement.pub_datetime.strftime("%m/%d/%Y, %H:%M:%S") +", " #TO_DO: fix timezone
response = response + announcement.title + " by " + announcement.author.first_name + " " + announcement.author.last_name #TO_DO: widgetUser functionality (parsing author info)
response = response + " published " + announcementpubdate + "<br>"
response = response + announcement.body + "<br>"
for reaction in all_reactions:
if reaction.announcement == announcement:
response = response + reaction.name + ": " + str(reaction.tally) + "<br>"
response = response + "<br>"
return HttpResponse(response)
# Create your views here.
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