Commit 1613af84 authored by Alec Dayupay's avatar Alec Dayupay

Added forum app, Fixed all apps, and Populated models

parent fc49b221
......@@ -16,6 +16,9 @@ Date of Submission: Monday, March 6, 2023
With the power of Big Django Energy, we were able to complete this project effectively in compliance with the project specs.
References:
https://www.geeksforgeeks.org/overriding-the-save-method-django-models/
<sgd> Neo Emmanuel D. Ballesteros, 3/2/2023
<sgd> Anthony P. Bicomong, 3/2/2023
<sgd> Kirsten Daena C. Chidrome, 3/2/2023
......
from django.contrib import admin
from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('title', 'body', 'author', 'pub_datetime')
search_fields = ('title', 'body', 'author', 'pub_datetime')
list_filter = ('title', 'body', 'author', 'pub_datetime')
class ReactionInline(admin.TabularInline):
model = Reaction
class AnnonuncementInline(admin.TabularInline):
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
list_display = ('title', 'body', 'author', 'pub_datetime',)
search_field = ('title', 'body', 'author', 'pub_datetime',)
inlines = [ReactionInline]
class ReactionAdmin(admin.ModelAdmin):
model = Reaction
list_display = ('name', 'tally', 'announcement')
search_fields = ('name', 'tally', 'announcement')
list_filter = ('name', 'tally', 'announcement')
class ReactionInline(admin.TabularInline):
model = Reaction
list_display = ('name', 'tally', 'announcement',)
search_field = ('name', 'tally', 'announcement',)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin)
\ No newline at end of file
# Generated by Django 3.2 on 2023-03-02 06:17
# Generated by Django 3.2 on 2023-03-03 15:39
from django.db import migrations, models
import django.db.models.deletion
......@@ -9,6 +9,7 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('dashboard', '0001_initial'),
]
operations = [
......@@ -17,17 +18,17 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('body', models.CharField(max_length=700)),
('author', models.CharField(max_length=200)),
('body', models.TextField()),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='Reaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('tally', models.IntegerField()),
('name', models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default='Like', max_length=50)),
('tally', models.IntegerField(default=0)),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')),
],
),
......
# Generated by Django 3.2 on 2023-03-02 08:53
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0001_initial'),
('announcements', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser'),
),
]
from django.db import models
from django.urls import reverse
class Announcement(models.Model):
title = models.CharField(max_length=50)
body = models.CharField(max_length=700)
title = models.CharField(max_length = 50)
body = models.TextField()
author = models.ForeignKey("dashboard.WidgetUser", on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
......@@ -11,8 +10,16 @@ class Announcement(models.Model):
return self.title
class Reaction(models.Model):
name = models.CharField(max_length=50)
tally = models.IntegerField()
Like = 'Like'
Love = 'Love'
Angry = 'Angry'
mode_options = [
(Like, 'Like'),
(Love, 'Love'),
(Angry, 'Angry'),
]
name = models.CharField(max_length = 50, choices=mode_options, default=Like)
tally = models.IntegerField(default = 0)
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
def __str__(self):
......
from django.shortcuts import render
from django.http import HttpResponse
from .models import Announcement, Reaction
def index(request):
all_announcements = Announcement.objects.all()
all_reactions = Reaction.objects.all()
announcements = Announcement.objects.all()
reactions = Reaction.objects.all()
response = "Big Django Energy - Announcement Board<br><br>Announcements:<br>"
for announcement in all_announcements:
announcementpubdate = announcement.pub_datetime.strftime("%m/%d/%Y, %H:%M:%S") +", "
response = response + announcement.title + " by " + announcement.author.__str__()
response = response + " published " + announcementpubdate + "<br>"
response = response + announcement.body + "<br>"
for reaction in all_reactions:
response = "Widget's Announcement Board<br><br>Announcements:<br>"
for announcement in announcements:
response += "{} by {} published {}:<br>{}<br>".format(
announcement.title,
announcement.author,
announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
announcement.body
)
for reaction in reactions:
if reaction.announcement == announcement:
response = response + reaction.name + ": " + str(reaction.tally) + "<br>"
response = response + "<br>"
response += "{}: {}<br>".format(
reaction.name,
str(reaction.tally)
)
response += "<br>"
return HttpResponse(response)
from django.contrib import admin
from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin):
class AssignmentInline(admin.TabularInline):
model = Assignment
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
list_display = ('name', 'description', 'course', 'perfect_score', 'passing_score',)
search_field = ('name', 'description', 'course', 'perfect_score', 'passing_score',)
class CourseAdmin(admin.ModelAdmin):
model = Course
list_display = ('code', 'title', 'section',)
search_field = ('code', 'title', 'section',)
inlines = [AssignmentInline]
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
# Generated by Django 4.1.7 on 2023-03-02 07:00
# Generated by Django 3.2 on 2023-03-03 15:39
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
......@@ -12,23 +13,23 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name='Assignment',
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=100, null=True)),
('description', models.TextField(blank=True, null=True)),
('course', models.CharField(blank=True, max_length=50, null=True)),
('perfect_score', models.IntegerField(blank=True, null=True)),
('passing_score', models.IntegerField(blank=True, null=True)),
('code', models.CharField(max_length=10)),
('title', models.CharField(max_length=50)),
('section', models.CharField(max_length=3)),
],
),
migrations.CreateModel(
name='Course',
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(blank=True, max_length=10, null=True)),
('title', models.CharField(blank=True, max_length=100, null=True)),
('section', models.CharField(blank=True, max_length=3, null=True)),
('name', models.CharField(max_length=50)),
('description', models.TextField()),
('perfect_score', models.IntegerField(default=0)),
('passing_score', models.IntegerField(default=0)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.course')),
],
),
]
from django.db import models
class Assignment(models.Model):
name = models.CharField(max_length = 100, blank = True, null = True)
description = models.TextField(blank = True, null = True)
course = models.CharField(max_length = 50, blank = True, null = True)
perfect_score = models.IntegerField(blank = True, null = True)
passing_score = models.IntegerField(blank = True, null = True)
class Course(models.Model):
code = models.CharField(max_length = 10)
title = models.CharField(max_length = 50)
section = models.CharField(max_length = 3)
def __str__(self):
return self.name
return "{} {}-{}".format(self.code, self.title, self.section)
class Assignment(models.Model):
name = models.CharField(max_length = 50)
description = models.TextField()
course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.IntegerField(default = 0)
passing_score = models.IntegerField(default = 0)
class Course(models.Model):
code = models.CharField(max_length = 10, blank = True, null = True)
title = models.CharField(max_length = 100, blank = True, null = True)
section = models.CharField(max_length = 3, blank = True, null = True)
def save(self, *args, **kwargs):
self.passing_score = round(self.perfect_score*0.6)
super(Assignment, self).save(*args, **kwargs)
def __str__(self):
return self.code
\ No newline at end of file
return self.name
\ No newline at end of file
from django.http import HttpResponse
from .models import Assignment, Course
from .models import Assignment
def index(request):
assignmentlist = Assignment.objects.all()
courselist = Course.objects.all()
response = "Widget's Assignment Page"
assignments = Assignment.objects.all()
i = 0
while i < len(assignmentlist):
response += f"<br><br>Assignment Name: {assignmentlist[i].name}" + f"<br>Description: {assignmentlist[i].description}" + f"<br>Perfect Score: {assignmentlist[i].perfect_score}" + f"<br>Passing Score: {assignmentlist[i].passing_score}<br>" + f"Course/Section: {courselist[i].code} {courselist[i].title}-{courselist[i].section}"
i+=1
response = "Widget's Assignment Page<br><br>"
for assignment in assignments:
response += "Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {}<br><br>".format(
assignment.name,
assignment.description,
assignment.perfect_score,
assignment.passing_score,
assignment.course
)
return HttpResponse(response)
\ No newline at end of file
from django.contrib import admin
from .models import Event, Location
# Register your models here.
class EventInline(admin.TabularInline):
model = Event
class EventAdmin(admin.ModelAdmin):
model = Event
list_display = ("target_datetime", "activity", "estimated_hours", "locations", "course",)
search_field = ("target_datetime", "activity", "estimated_hours", "locations", "course",)
list_filter = ("target_datetime", "activity", "estimated_hours", "locations", "course",)
class LocationAdmin(admin.ModelAdmin):
model = Location
list_display = ("modes", "venue",)
search_field = ("modes", "venue",)
list_filter = ("venue",)
inlines = [EventInline]
admin.site.register(Event, EventAdmin)
admin.site.register(Location, LocationAdmin)
# Generated by Django 3.2 on 2023-03-02 07:20
# Generated by Django 3.2 on 2023-03-03 15:39
from django.db import migrations, models
import django.db.models.deletion
......@@ -9,25 +9,27 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('assignments', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Event',
name='Location',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('target_datetime', models.DateTimeField(verbose_name='Target Date & Time')),
('activity', models.CharField(max_length=300)),
('estimated_hours', models.FloatField(default=0)),
('locations', models.CharField(max_length=300)),
('course', models.CharField(max_length=300)),
('modes', models.CharField(choices=[('Onsite', 'Onsite'), ('Online', 'Online'), ('Hybrid', 'Hybrid')], default='Onsite', max_length=50)),
('venue', models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name='Location',
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('venue', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='calendars.event')),
('target_datetime', models.DateTimeField()),
('activity', models.CharField(max_length=50)),
('estimated_hours', models.FloatField(default=0)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.course')),
('locations', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='calendars.location')),
],
),
]
# Generated by Django 3.2 on 2023-03-02 07:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('calendars', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='location',
name='modes',
field=models.CharField(choices=[('onsite', 'onsite'), ('online', 'online')], default='onsite', max_length=150),
),
]
# Generated by Django 3.2 on 2023-03-02 08:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('calendars', '0002_location_modes'),
]
operations = [
migrations.AlterField(
model_name='location',
name='venue',
field=models.CharField(max_length=200),
),
]
# Generated by Django 3.2 on 2023-03-02 08:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('calendars', '0003_alter_location_venue'),
]
operations = [
migrations.AlterField(
model_name='location',
name='venue',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='calendars.event'),
),
]
# Generated by Django 3.2 on 2023-03-02 08:11
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('calendars', '0004_alter_location_venue'),
]
operations = [
migrations.AlterField(
model_name='event',
name='locations',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='calendars.location'),
),
migrations.AlterField(
model_name='location',
name='venue',
field=models.CharField(max_length=150),
),
]
from django.db import models
# Create your models here.
class Location(models.Model):
Onsite = 'onsite'
Online = 'online'
Onsite = 'Onsite'
Online = 'Online'
Hybrid = 'Hybrid'
mode_options = [
(Onsite, 'onsite'),
(Online, 'online'),
(Onsite, 'Onsite'),
(Online, 'Online'),
(Hybrid, 'Hybrid'),
]
modes = models.CharField(max_length=150, choices=mode_options, default=Onsite)
venue = models.CharField(max_length=150)
modes = models.CharField(max_length = 50, choices=mode_options, default=Onsite)
venue = models.CharField(max_length = 50)
def __str__(self):
return self.venue
class Event(models.Model):
target_datetime = models.DateTimeField("Target Date & Time")
activity = models.CharField(max_length=300)
target_datetime = models.DateTimeField()
activity = models.CharField(max_length = 50)
estimated_hours = models.FloatField(default=0)
locations = models.ForeignKey(Location, on_delete=models.CASCADE)
course = models.CharField(max_length=300)
course = models.ForeignKey('assignments.Course', on_delete=models.CASCADE)
def __str__(self):
return self.activity
# models.ForeignKeys('assignments.Course', on_delete=models.CASCADE)
return self.activity
\ No newline at end of file
......@@ -2,5 +2,5 @@ from django.urls import path
from . import views
urlpatterns = [
path('', views.calendarschedule, name = "calendarschedule")
path('', views.index, name = "index")
]
\ No newline at end of file
from django.http import HttpResponse
from .models import Event
# Create your views here.
def calendarschedule(request):
schedule = Event.objects.all()
response ="Widgets's Calendar of Activities<br><br>"
for sched in schedule:
datetime = sched.target_datetime.strftime("%m/%d/%Y, %H:%M %p")
activities = sched.activity
estimatedhrs = str(sched.estimated_hours)
courses = sched.course
mode = sched.locations.modes
ven = sched.locations.venue
response += "Date and Time: "+ datetime + "<br>Activity: " + activities + "<br>Estimated Hours: " + estimatedhrs +"<br>Course/Section: " + courses + "<br>Mode: " + mode + "<br>Venue: " + ven + "<br>"
def index(request):
events = Event.objects.all()
response ="Widgets's Calendar of Activities<br><br>Date and Time: "
for event in events:
response += "{}<br>Activity: {}<br>Estimated Hours: {}<br>Course/Section: {}<br>Mode: {}<br>Venue: {}<br>".format(
event.target_datetime.strftime("%m/%d/%Y, %I:%M %p"),
event.activity,
str(event.estimated_hours),
event.course,
event.locations.modes,
event.locations.venue
)
return HttpResponse(response)
\ No newline at end of file
from django.contrib import admin
from .models import Department, WidgetUser
from .models import department, widgetUser
class WidgetUserInline(admin.TabularInline):
model = WidgetUser
class departmentAdmin(admin.ModelAdmin):
model = department
search_fields = ('dept_name', 'home_unit')
class DepartmentAdmin(admin.ModelAdmin):
model = Department
list_display = ('dept_name', 'home_unit')
list_filter = ('dept_name', 'home_unit')
search_field = ('dept_name', 'home_unit')
inlines = [WidgetUserInline]
class widgetUsersAdmin(admin.ModelAdmin):
model = widgetUser
search_fields = ('first_name', 'middle_name', 'last_name', 'department')
list_display = ('first_name', 'last_name', 'department')
list_filter = ('first_name', 'last_name', 'department')
class WidgetUsersAdmin(admin.ModelAdmin):
model = WidgetUser
list_display = ('first_name', 'middle_name', 'last_name', 'department')
search_field = ('first_name', 'middle_name', 'last_name', 'department')
admin.site.register(department, departmentAdmin)
admin.site.register(widgetUser, widgetUsersAdmin)
\ No newline at end of file
admin.site.register(Department, DepartmentAdmin)
admin.site.register(WidgetUser, WidgetUsersAdmin)
\ No newline at end of file
# Generated by Django 3.2 on 2023-03-02 07:28
# Generated by Django 3.2 on 2023-03-03 15:38
from django.db import migrations, models
import django.db.models.deletion
......@@ -13,20 +13,20 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name='department',
name='Department',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('dept_name', models.CharField(max_length=100)),
('home_unit', models.CharField(max_length=100)),
('dept_name', models.CharField(max_length=50)),
('home_unit', models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name='widgetUser',
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=100)),
('middle_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
('first_name', models.CharField(max_length=50)),
('middle_name', models.CharField(max_length=50)),
('last_name', models.CharField(max_length=50)),
('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.department')),
],
),
......
from django.db import models
from django.urls import reverse
class department(models.Model):
dept_name = models.CharField(max_length = 100)
home_unit = models.CharField(max_length = 100, )
class Department(models.Model):
dept_name = models.CharField(max_length = 50)
home_unit = models.CharField(max_length = 50)
def __str__(self):
return '{}'.format(self.dept_name)
return self.dept_name
def get_absolute_url(self):
return reverse('department', args= [str(self.dept_name)])
class widgetUser(models.Model):
first_name = models.CharField(max_length = 100)
middle_name = models.CharField(max_length = 100)
last_name = models.CharField(max_length = 100)
department = models.ForeignKey(
department,
on_delete = models.CASCADE,)
class WidgetUser(models.Model):
first_name = models.CharField(max_length = 50)
middle_name = models.CharField(max_length = 50)
last_name = models.CharField(max_length = 50)
department = models.ForeignKey(Department, on_delete = models.CASCADE)
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('widgetUser', args= [str(self.last_name)])
\ No newline at end of file
return '{} {}'.format(self.first_name, self.last_name)
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import department, widgetUser
from .models import Department, WidgetUser
def dashboard(request):
welcome_message = "Welcome to Widget!<br><br>WIDGET USERS:<br>"
all_widgetUser = widgetUser.objects.all()
for member in all_widgetUser:
last_name = member.last_name
first_name = member.first_name
middle_name = member.middle_name
dept_name = member.department.dept_name
home_unit = member.department.home_unit
output = "{lastName}, {firstName} {middleName}: {deptName}, {homeUnit}<br>".format(lastName = last_name, firstName = first_name, middleName = middle_name, deptName = dept_name, homeUnit = home_unit)
welcome_message += output
widgetusers = WidgetUser.objects.all()
response = "Welcome to Widget!<br><br>WIDGET USERS:<br>"
for user in widgetusers:
response += "{}, {} {}: {}, {}<br>".format(
user.last_name,
user.first_name,
user.middle_name,
user.department,
user.department.home_unit
)
return HttpResponse(welcome_message)
\ No newline at end of file
return HttpResponse(response)
\ No newline at end of file
from django.contrib import admin
from .models import ForumPost, Reply
# Register your models here.
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
list_display = ("title", "body", "author", "pub_datetime",)
search_field = ("title", "body", "author", "pub_datetime",)
class ReplyAdmin(admin.ModelAdmin):
model = Reply
list_display = ("body", "author", "pub_datetime",)
search_field = ("body", "author", "pub_datetime",)
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
# Generated by Django 3.2 on 2023-03-03 15:39
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dashboard', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField()),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='ForumPost',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('body', models.TextField()),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
],
),
]
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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