Commit 70b0fc23 authored by iceman2434's avatar iceman2434

Modified forum class and added reply class

Changed forum class name to post
Added reply class
parent d7c88b7b
from django.contrib import admin
from .models import WidgetUser, Forum, Announcement, Assignment
from .models import WidgetUser, Post, Reply, Announcement, Assignment, Department
# Classes
class DepartmentInline(admin.TabularInline):
model = Department
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': [
'id_num',
'first_name',
'middle_name',
'last_name'
'last_name',
'email'
]
}),
]
inlines = [DepartmentInline,]
class DepartmentAdmin(admin.ModelAdmin):
model = Department
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
......@@ -38,22 +44,43 @@ class AnnouncementAdmin(admin.ModelAdmin):
})
]
class ForumAdmin(admin.ModelAdmin):
model = Forum
class ReplyInline(admin.TabularInline):
model = Reply
search_fields = ('post_title', 'post_body', 'pub_date')
list_display = ('post_title', 'post_body', 'pub_date')
list_filter = ('post_title', 'post_body', 'pub_date')
class PostAdmin(admin.ModelAdmin):
model = Post
search_fields = ('post_title', 'post_body', 'pub_date', 'author')
list_display = ('post_title', 'post_body', 'pub_date', 'author')
list_filter = ('post_title', 'post_body', 'pub_date', 'author')
fieldsets = [
('Forum Data', {
('Post Data', {
'fields': [
'post_title',
'post_body',
'author',
]
}),
]
inlines = [ReplyInline,]
class ReplyAdmin(admin.ModelAdmin):
model = Reply
search_fields = ('reply_body', 'pub_date', 'author')
list_display = ('reply_body', 'pub_date', 'author')
list_filter = ('reply_body', 'pub_date', 'author')
fieldsets = [
('Reply Data', {
'fields': [
'reply_body',
'author',
]
}),
]
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
......@@ -87,6 +114,7 @@ class AssignmentAdmin(admin.ModelAdmin):
# Register models
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Forum, ForumAdmin)
admin.site.register(Post, PostAdmin)
admin.site.register(Reply, ReplyAdmin)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Assignment, AssignmentAdmin)
......@@ -2,20 +2,29 @@ from django.db import models
from django.urls import reverse
class WidgetUser(models.Model):
id_num = models.IntegerField()
first_name = models.CharField(max_length=100)
middle_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email = models.EmailField()
def __str__(self):
return self.full_name
return '{}, {} {}: {}, {}'.format(self.last_name, self.first_name, self.middle_name, self.id_num, self.email)
def get_absolute_url(self):
return reverse('widget_user', args=[(self.full_name)])
@property
def full_name(self):
return '{} {} {}'.format(self.first_name, self.middle_name, self.last_name)
class Department(models.Model):
dept_name = models.CharField(max_length=100)
home_unit = models.CharField(max_length=100)
widget_user = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
def __str__(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class Announcement(models.Model):
announcement_title= models.CharField(max_length=50)
announcement_body = models.CharField(max_length=200)
......@@ -31,18 +40,27 @@ class Announcement(models.Model):
def full_announcement(self):
return '{} {} {}'.format(self.announcement_title, self.announcement_body, self.pub_date)
class Forum(models.Model):
class Post(models.Model):
post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=100)
pub_date = models.DateTimeField(auto_now_add=True, editable=False)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
def __str__(self):
return self.post_title
return '{} by {} dated {}:\n {}'.format(self.post_title, self.author.get_absolute_url(), self.pub_date, self.post_body)
def get_absolute_url(self):
return reverse('forum', args=[(self.post_title)])
class Reply(models.Model):
reply_body = models.CharField(max_length=100)
pub_date = models.DateTimeField(auto_now_add=True, editable=False)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
replied_post = models.ForeignKey(Post, on_delete=models.CASCADE)
def __str__(self):
return 'Reply by {} dated {}:\n {}'.format(self.author.get_absolute_url(), self.pub_date, self.reply_body)
class Assignment(models.Model):
name = models.CharField(max_length = 100)
description = models.CharField(max_length = 200)
......
......@@ -22,5 +22,5 @@ urlpatterns = [
path('', homepage, name='homepage'),
path('assignments/', assignments, name='assignments'),
path('announcements/', announcements, name='Announcement Board'),
path('forum/', forum, name='forum')
path('forum/', forum, name='Forum')
]
from django.http import HttpResponse
from .models import WidgetUser, Post, Reply, Announcement, Assignment, Department
def homepage(request):
return HttpResponse('Welcome to Widget!')
widget_users = WidgetUser.objects.all()
output = "WIDGET USERS:\n" + "\n".join([str(user) for user in widget_users])
return HttpResponse(output, content_type="text/plain")
def assignments(request):
return HttpResponse('This is the Assignments page!')
......@@ -10,4 +13,7 @@ def announcements(request):
return HttpResponse('This is the Announcement Board!')
def forum(request):
return HttpResponse('Welcome to Widget’s Forum!')
post = Post.objects.all()
reply = Reply.objects.all()
output = "FORUM POSTS:\n" + "\n".join([str(x) for x in post]) + "\n".join([str(z) for z in reply])
return HttpResponse(output, content_type="text/plain")
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