Commit c1678528 authored by Joshua de Vera's avatar Joshua de Vera

Announcement Models

Updated admin.py models.py views.py to accomodate midterm specifications for the Announcements section
parent 39f72de6
File added
from django.contrib import admin from django.contrib import admin
from .models import WidgetUser, Forum, Announcement from .models import WidgetUser, Forum, Announcement, Assignment
# Classes # Classes
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
search_fields = ('first_name', 'middle_name', 'last_name')
list_display = ('first_name', 'middle_name', 'last_name')
list_filter = ('first_name', 'middle_name', 'last_name')
fieldsets = [
('Widget User Data', {
'fields': [
'first_name',
'middle_name',
'last_name'
]
}),
]
class AnnouncementAdmin(admin.ModelAdmin): class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement model = Announcement
search_fields = ('announcement_title', 'announcement_body', 'pub_date') search_fields = ('announcement_title', 'announcement_body', 'authors_First_Name', 'authors_Last_Name', 'pub_date')
list_display = ('announcement_title', 'announcement_body', 'pub_date') list_display = ('announcement_title', 'announcement_body', 'authors_First_Name', 'authors_Last_Name', 'pub_date')
list_filter = ('announcement_title', 'announcement_body', 'pub_date') list_filter = ('announcement_title', 'announcement_body', 'authors_First_Name', 'authors_Last_Name', 'pub_date')
fieldsets = [ fieldsets = [
('Announcement Data', { ('Announcement Data', {
'fields': [ 'fields': [
'announcement_title', 'announcement_title',
'announcement_body', 'announcement_body',
'authors_First_Name',
'authors_Last_Name',
'pub_date',
] ]
}) })
] ]
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
class WidgetUserAdmin(admin.ModelAdmin): search_fields = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
model = WidgetUser list_display = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
list_filter = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
search_fields = ('first_name', 'middle_name', 'last_name') fieldsets = [
list_display = ('first_name', 'middle_name', 'last_name') ('Department Data', {
list_filter = ('first_name', 'middle_name', 'last_name') 'fields': [
'reaction_name1',
'tally1',
'reaction_name2',
'tally2',
'reaction_name3',
'tally3',
]
}),
]
class ForumAdmin(admin.ModelAdmin):
model = Forum
search_fields = ('post_title', 'post_body', 'pub_date')
list_display = ('post_title', 'post_body', 'pub_date')
list_filter = ('post_title', 'post_body', 'pub_date')
fieldsets = [ fieldsets = [
('Widget User Data', { ('Forum Data', {
'fields': [ 'fields': [
'first_name', 'post_title',
'middle_name', 'post_body',
'last_name'
] ]
}), }),
] ]
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
search_fields = ('name', 'description', 'max_points')
list_display = ('name', 'description', 'max_points')
list_filter = ('name', 'description', 'max_points')
fieldsets = [
('Assignment Data', {
'fields': [
'name',
'description',
'max_points'
]
}
)
]
...@@ -46,3 +113,4 @@ class WidgetUserAdmin(admin.ModelAdmin): ...@@ -46,3 +113,4 @@ class WidgetUserAdmin(admin.ModelAdmin):
admin.site.register(WidgetUser, WidgetUserAdmin) admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Forum, ForumAdmin) admin.site.register(Forum, ForumAdmin)
admin.site.register(Announcement, AnnouncementAdmin) admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Assignment, AssignmentAdmin)
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
class Reaction(models.Model):
reaction_name1 = models.CharField(max_length=15)
tally1 = models.IntegerField(max_length=3)
reaction_name2 = models.CharField(max_length=15)
tally2 = models.IntegerField(max_length=3)
reaction_name3 = models.CharField(max_length=15)
tally3 = models.IntegerField(max_length=3)
class Announcement(models.Model): class Announcement(models.Model):
announcement_title= models.CharField(max_length=50) announcement_title= models.CharField(max_length=50)
announcement_body = models.CharField(max_length=200) announcement_body = models.CharField(max_length=200)
authors_First_Name = models.CharField(max_length=20)
authors_Last_Name = models.CharField(max length=20)
pub_date = models.DateTimeField(auto_now_add=True, editable=False) pub_date = models.DateTimeField(auto_now_add=True, editable=False)
reaction = models.ForeignKey(Reaction, on_delete=models.CASCADE, default=1)
def __str__(self):
return self.full_announcement
def get_absolute_url(self): def get_absolute_url(self):
return reverse('Announcement', args=[(self.full_announcement)]) return reverse('Announcement', args=[(self.full_announcement)])
......
...@@ -5,6 +5,24 @@ def homepage(request): ...@@ -5,6 +5,24 @@ def homepage(request):
def assignments(request): def assignments(request):
return HttpResponse('This is the Assignments page!') return HttpResponse('This is the Assignments page!')
announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
output = "ANNOUNCEMENTS:\n" + "\n".join(
['{} by {} {} dated by {}: \n {} \n {}: {} \n {}: {} \n {}: {}'.format(
str(announcements.announcement_title),
str(announcements.authors_First_Name),
str(announcements.authors_Last_Name),
str(announcements.pub_date),
str(announcements.announcement_body),
str(reactions.reaction_name1),
str(reactions.tally1),
str(reactions.reaction_name2),
str(reactions.tally3),
str(reactions.reaction_name3),
)
for announcement in announcements]
)
def announcements(request): def announcements(request):
return HttpResponse('This is the Announcement Board!') return HttpResponse('This is the 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