Commit da596da1 authored by Deokhyun Lee's avatar Deokhyun Lee

code general format is now clear and concise.

parent f88bc03e
File added
from django.contrib import admin from django.contrib import admin
from .models import Announcement, Reaction from .models import Announcement, Reaction
class ReactionInline(admin.TabularInline): class ReactionInline(admin.TabularInline):
model = Reaction model = Reaction
# admin panel for Announcemnet model
class AnnouncementAdmin(admin.ModelAdmin): class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement model = Announcement
...@@ -12,13 +14,13 @@ class AnnouncementAdmin(admin.ModelAdmin): ...@@ -12,13 +14,13 @@ class AnnouncementAdmin(admin.ModelAdmin):
list_filter = ('title', 'author', 'pub_datetime',) list_filter = ('title', 'author', 'pub_datetime',)
inlines = [ReactionInline,] inlines = [ReactionInline,]
# admin panel for Reaction model
class ReactionAdmin(admin.ModelAdmin): class ReactionAdmin(admin.ModelAdmin):
model = Reaction model = Reaction
search_fields = ('name', 'announcement',) search_fields = ('name', 'announcement',)
list_display = ('name', 'tally', 'announcement',) list_display = ('name', 'tally', 'announcement',)
list_filter = ('name', 'tally',) list_filter = ('name', 'tally',)
admin.site.register(Announcement, AnnouncementAdmin) admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin) admin.site.register(Reaction, ReactionAdmin)
from django.db import models from django.db import models
from dashboard.models import WidgetUser from dashboard.models import WidgetUser
# Announcement
# title; body; author; pub_datetime
class Announcement(models.Model): class Announcement(models.Model):
title = models.CharField(max_length=50) title = models.CharField(max_length=50)
body = models.TextField(max_length=420) body = models.TextField(max_length=420)
...@@ -10,6 +12,9 @@ class Announcement(models.Model): ...@@ -10,6 +12,9 @@ class Announcement(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title
# Reaction
# name; tally; announcement;
class Reaction(models.Model): class Reaction(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
tally = models.IntegerField(default=0) tally = models.IntegerField(default=0)
......
#announcements/urls.py
from django.urls import path from django.urls import path
from .import views from .import views
urlpatterns = [
# url for announcement
urlpatterns = [
path("", views.announcement_boardIndex, name = "announcement_boardIndex") path("", views.announcement_boardIndex, name = "announcement_boardIndex")
] ]
app_name = "announcement_board" app_name = "announcement_board"
\ No newline at end of file
...@@ -2,6 +2,7 @@ from django.http import HttpResponse ...@@ -2,6 +2,7 @@ from django.http import HttpResponse
from .models import Announcement, Reaction from .models import Announcement, Reaction
# announcemnet view from .models
def announcement_boardIndex(request): def announcement_boardIndex(request):
announcements = Announcement.objects.all() announcements = Announcement.objects.all()
reactions = Reaction.objects.all() reactions = Reaction.objects.all()
......
from django.urls import path from django.urls import path
from . import views from . import views
# url for homepage # url for assignments
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', views.assignmentIndex, name='assignmentIndex'),
] ]
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Assignment, Course from .models import Assignment
# Create your views here.
def index(request): # assignment view from .models
def assignmentIndex(request):
title = "Widget's Assignments Page" + "<br><br>" title = "Widget's Assignments Page" + "<br><br>"
assignments = Assignment.objects.all() assignments = Assignment.objects.all()
# courses = Course.objects.all()
output_view = "" output_view = ""
for assignment in assignments: for assignment in assignments:
name = "Assignment Name: " + assignment.name + "<br>" name = "Assignment Name: " + assignment.name + "<br>"
......
from django.db import models from django.db import models
from assignments.models import Course from assignments.models import Course
#Location Choices # Location Choices
location_choices = [ location_choices = [
('onsite', 'ONSITE'), ('onsite', 'ONSITE'),
('online', 'ONLINE'), ('online', 'ONLINE'),
...@@ -11,9 +11,8 @@ location_choices = [ ...@@ -11,9 +11,8 @@ location_choices = [
# Location # Location
# mode; venue; # mode; venue;
class Location(models.Model): class Location(models.Model):
mode = models.CharField(max_length=50, choices = location_choices, default = 'onsite') mode = models.CharField(max_length = 50, choices = location_choices, default = 'onsite')
venue = models.TextField(max_length=50) venue = models.TextField(max_length = 50)
def __str__(self): def __str__(self):
return self.venue return self.venue
...@@ -21,11 +20,11 @@ class Location(models.Model): ...@@ -21,11 +20,11 @@ class Location(models.Model):
# Event # Event
# target_datetime; activity; estimated_hours; location; course # target_datetime; activity; estimated_hours; location; course
class Event(models.Model): class Event(models.Model):
target_datetime = models.DateTimeField("Date and Time: ", max_length=50) target_datetime = models.DateTimeField("Date and Time: ", max_length = 50)
activity = models.CharField("Activity: ",max_length=50) activity = models.CharField("Activity: ", max_length = 50)
estimated_hours = models.FloatField("Estimated Hours: ",max_length=50) estimated_hours = models.FloatField("Estimated Hours: ", max_length = 50)
location = models.ForeignKey(Location, on_delete=models.CASCADE) location = models.ForeignKey(Location, on_delete = models.CASCADE)
course = models.ForeignKey(Course, on_delete=models.CASCADE) course = models.ForeignKey(Course, on_delete = models.CASCADE)
def __str__(self): def __str__(self):
return self.activity return self.activity
......
from django.urls import path from django.urls import path
from . import views from . import views
# url for homepage # url for calendar
urlpatterns = [ urlpatterns = [
path('', views.calendarIndex, name='calendarIndex'), path('', views.calendarIndex, name='calendarIndex'),
] ]
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Event, Location from .models import Event, Location
# calendar view from .models
def calendarIndex(request): def calendarIndex(request):
title = 'Widget’s Calendar of Activities<br><br>' title = 'Widget’s Calendar of Activities<br><br>'
events = Event.objects.all() events = Event.objects.all()
......
from django.db import models from django.db import models
# Created Department model # Department
# dept_name; home_unit
class Department(models.Model): class Department(models.Model):
dept_name = models.CharField(max_length = 100) dept_name = models.CharField(max_length = 100)
home_unit = models.CharField(max_length = 100) home_unit = models.CharField(max_length = 100)
...@@ -10,7 +11,8 @@ class Department(models.Model): ...@@ -10,7 +11,8 @@ class Department(models.Model):
# Created WidgetUser model # WidgetUser
# first_name; middle_name; last_name; department;
class WidgetUser(models.Model): class WidgetUser(models.Model):
first_name = models.CharField(max_length = 50) first_name = models.CharField(max_length = 50)
middle_name = models.CharField(max_length = 50) middle_name = models.CharField(max_length = 50)
......
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
from django.urls import path from django.urls import path
from .import views from .import views
# url for dashboard
urlpatterns = [ urlpatterns = [
path("", views.dashboardIndex, name = "dashboardIndex") path("", views.dashboardIndex, name = "dashboardIndex")
] ]
app_name = "dashboard" app_name = "dashboard"
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Department, WidgetUser from .models import Department, WidgetUser
# dashboard view from .models
def dashboardIndex(request): def dashboardIndex(request):
users = WidgetUser.objects.all() users = WidgetUser.objects.all()
departments = Department.objects.all() departments = Department.objects.all()
...@@ -11,9 +12,6 @@ def dashboardIndex(request): ...@@ -11,9 +12,6 @@ def dashboardIndex(request):
home_department = str(user.department) home_department = str(user.department)
dashboard_output = dashboard_output + username + ": " + home_department + "<br>" dashboard_output = dashboard_output + username + ": " + home_department + "<br>"
return HttpResponse(dashboard_output) return HttpResponse(dashboard_output)
......
...@@ -4,13 +4,13 @@ from .models import ForumPost, Reply ...@@ -4,13 +4,13 @@ from .models import ForumPost, Reply
class ReplyInLine(admin.TabularInline): class ReplyInLine(admin.TabularInline):
model = Reply model = Reply
# admin panel for Forum model
class ForumPostAdmin(admin.ModelAdmin): class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost model = ForumPost
list_display = ("title", "author", "body", "pub_datetime") list_display = ("title", "author", "body", "pub_datetime")
inlines = [ReplyInLine] inlines = [ReplyInLine]
# admin panel for Reply model
class ReplyAdmin(admin.ModelAdmin): class ReplyAdmin(admin.ModelAdmin):
list_display = ("forum_post", "author", "body", "pub_datetime") list_display = ("forum_post", "author", "body", "pub_datetime")
......
from django.db import models from django.db import models
from dashboard.models import WidgetUser from dashboard.models import WidgetUser
# Forum Post
# title; body; author; pub_datetime;
class ForumPost(models.Model): class ForumPost(models.Model):
title = models.CharField(max_length = 50) title = models.CharField(max_length = 50)
body = models.TextField(max_length = 1000) body = models.TextField(max_length = 1000)
...@@ -10,7 +12,8 @@ class ForumPost(models.Model): ...@@ -10,7 +12,8 @@ class ForumPost(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title
# Reply
# body; author; pub_datetime; forum_post;
class Reply(models.Model): class Reply(models.Model):
body = models.CharField(max_length=1000) body = models.CharField(max_length=1000)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
......
from django.urls import path from django.urls import path
from . import views from . import views
# url for forum
urlpatterns = [ urlpatterns = [
path("", views.forumIndex, name="forumIndex"), path("", views.forumIndex, name="forumIndex"),
] ]
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import ForumPost, Reply from .models import ForumPost, Reply
# forum view from .models
def forumIndex(request): def forumIndex(request):
# fetch forum posts and replies # fetch forum posts and replies
......
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