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 .models import WidgetUser, Forum, Announcement
from .models import WidgetUser, Forum, Announcement, Assignment
# 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):
model = Announcement
search_fields = ('announcement_title', 'announcement_body', 'pub_date')
list_display = ('announcement_title', 'announcement_body', 'pub_date')
list_filter = ('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', 'authors_First_Name', 'authors_Last_Name', 'pub_date')
list_filter = ('announcement_title', 'announcement_body', 'authors_First_Name', 'authors_Last_Name', 'pub_date')
fieldsets = [
('Announcement Data', {
'fields': [
'announcement_title',
'announcement_body',
'authors_First_Name',
'authors_Last_Name',
'pub_date',
]
})
]
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
search_fields = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
list_display = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
list_filter = ('reaction_name1', 'tally1', 'reaction_name2', 'tally2', 'reaction_name3', 'tally3')
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
fieldsets = [
('Department Data', {
'fields': [
'reaction_name1',
'tally1',
'reaction_name2',
'tally2',
'reaction_name3',
'tally3',
]
}),
]
search_fields = ('first_name', 'middle_name', 'last_name')
list_display = ('first_name', 'middle_name', 'last_name')
list_filter = ('first_name', 'middle_name', 'last_name')
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 = [
('Widget User Data', {
('Forum Data', {
'fields': [
'first_name',
'middle_name',
'last_name'
'post_title',
'post_body',
]
}),
]
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):
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Forum, ForumAdmin)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Assignment, AssignmentAdmin)
from django.db import models
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):
announcement_title= models.CharField(max_length=50)
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)
def __str__(self):
return self.full_announcement
reaction = models.ForeignKey(Reaction, on_delete=models.CASCADE, default=1)
def get_absolute_url(self):
return reverse('Announcement', args=[(self.full_announcement)])
......@@ -15,7 +24,7 @@ class Announcement(models.Model):
@property
def full_announcement(self):
return '{} {} {}'.format(self.announcement_title, self.announcement_body, self.pub_date)
class Forum(models.Model):
post_title = models.CharField(max_length=50)
......
......@@ -5,6 +5,24 @@ def homepage(request):
def assignments(request):
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):
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