Commit 18b6b350 authored by Brescia Amandy's avatar Brescia Amandy

Merge branch 'Announcement_Board' into 'master'

Announcement board

See merge request !5
parents 20150d91 2a99b6a5
from django.contrib import admin
from .models import Reaction,Announcement
# Register your models here.
class ReactionInLine(admin.TabularInline):
model = Reaction
extra = 1
class AnnouncementAdmin(admin.ModelAdmin):
inlines = [ReactionInLine,]
list_display = ('title', 'author', 'pub_datetime', 'body')
search_fields = ('title', 'author', 'body')
list_filter = ('author', 'pub_datetime')
from django.apps import AppConfig
class AnnouncementBoardConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Announcement_Board'
from django.db import models
from django.urls import reverse
from dashboard.model import WidgetUser
# Create your models here.
class Announcement(models.Model):
title = models.CharField(max_length = 50)
body = models.TextField()
author = models.ForeignKey(
WidgetUser,
on_delete = models.CASCADE
)
pub_datetime = models.DateTimeField()
class Reaction(models.Model):
name = models.CharField(max_length = 50)
tally = models.IntegerField()
announcement = models.ForeignKey(
Announcement,
on_delete = models.CASCADE
)
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.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here.
def index(request):
return_string = '<body> <ul>'
reaction_string = ''
for announcement in Announcement.objects.all():
announcement_string = '<li>{} by {} published <br>{}</li>'.format(
announcement.title, announcement.author, announcement.pub_datetime.strftime('%m/%d/%Y %H:%M %p'),
announcement.body
)
for reaction in Reaction.objects.all():
if reaction.announcement == announcement:
reaction_string += '<li>{}: {}</li>'.format(reaction.name, reaction.tally
)
return_string += announcement_string
return_string += reaction_string
return_string += '<br>'
return_string += '</ul></body>'
html_string = '<htmk>{}</html>'.format(return_string)
return HttpResponse(html_string)
\ No newline at end of file
......@@ -39,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Announcement_Board',
]
MIDDLEWARE = [
......
......@@ -14,9 +14,11 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.urls import include, path
urlpatterns = [
path('dashboard', include('dashboard.urls')),
path('Announcement_Board/', include('Announcement_Board.urls', namespace="Announcement_Board" )),
path('dashboard', include('dashboard.urls', namespace="dashboard")),
path('admin/', admin.site.urls),
]
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