Commit d7c73665 authored by Tanya's avatar Tanya

merged changes from master to forum

parents b3b723d5 a4cbb052
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_dsiplay = ("title","body","author","pub_datetime")
search_fields = ("title", "author")
list_filter = ("title","author")
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_dsiplay = ("name","tally","announcement")
search_fields = ("name","announcement")
list_filter = ("name","announcement")
admin.site.register(Announcement,AnnouncementAdmin)
admin.site.register(Reaction,ReactionAdmin)
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-06 03:20
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(default='', max_length=100)),
('body', models.TextField(default='')),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(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(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], max_length=6)),
('tally', models.IntegerField(default=0)),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcement_board.announcement')),
],
),
]
from django.db import models
from dashboard.models import WidgetUser
class Announcement(models.Model):
title = models.CharField(max_length=100,default="")
body = models.TextField(default="")
author = models.CharField(max_length=100, unique=True,default="")
author = models.ForeignKey(WidgetUser,on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
def __str__(self):
return '{} by {}'.format(self.title, self.author)
class Reaction(models.Model):
name = models.CharField(max_length=20,default="")
reactions = [('Like','Like'),
("Love", 'Love'),
('Angry', 'Angry')
]
name = models.CharField(choices=reactions,max_length=6)
tally = models.IntegerField(default=0)
announcement = models.ForeignKey(Announcement,on_delete=models.CASCADE)
def __str__(self):
return '{} reaction in "{}"'.format(self.name, self.announcement.title)
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'
from django.http import HttpResponse
from .models import Announcement, Reaction
from dashboard.models import WidgetUser
def index(request):
return_string = '<body>'
for announcement in Announcement.objects.all():
announcement_heading = '{} by {} {} published {}:<br>'.format(
announcement.title,
announcement.author.first_name,
announcement.author.last_name,
announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p")
)
announcement_body = '{}<br>'.format(announcement.body)
announcement_reactions = ''
announcement_reactions += 'Like: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Like').tally)
announcement_reactions += 'Love: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Love').tally)
announcement_reactions += 'Angry: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Angry').tally)
return_string += announcement_heading + announcement_body + announcement_reactions +'<br>'
html_string ='<html>{}</html>'.format(return_string)
return HttpResponse('Widget’s Announcement Board<br><br>Announcements:<br>'+html_string)
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse
def index(request): def index(request):
return HttpResponse('Hello! This is the Forum.') return HttpResponse('Hello! This is the Forum.')
\ No newline at end of file
...@@ -41,6 +41,7 @@ INSTALLED_APPS = [ ...@@ -41,6 +41,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'announcement_board',
'dashboard', 'dashboard',
] ]
......
...@@ -20,4 +20,5 @@ urlpatterns = [ ...@@ -20,4 +20,5 @@ urlpatterns = [
path('dashboard/', include('dashboard.urls', namespace="dashboard")), path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('forum/', include('forum.urls', namespace="forum")), path('forum/', include('forum.urls', namespace="forum")),
path('announcements/', 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