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 ...@@ -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. 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> Neo Emmanuel D. Ballesteros, 3/2/2023
<sgd> Anthony P. Bicomong, 3/2/2023 <sgd> Anthony P. Bicomong, 3/2/2023
<sgd> Kirsten Daena C. Chidrome, 3/2/2023 <sgd> Kirsten Daena C. Chidrome, 3/2/2023
......
from django.contrib import admin from django.contrib import admin
from .models import Announcement, Reaction from .models import Announcement, Reaction
class AnnouncementAdmin(admin.ModelAdmin): class ReactionInline(admin.TabularInline):
model = Announcement model = Reaction
list_display = ('title', 'body', 'author', 'pub_datetime')
search_fields = ('title', 'body', 'author', 'pub_datetime')
list_filter = ('title', 'body', 'author', 'pub_datetime')
class AnnonuncementInline(admin.TabularInline): class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement model = Announcement
list_display = ('title', 'body', 'author', 'pub_datetime',)
search_field = ('title', 'body', 'author', 'pub_datetime',)
inlines = [ReactionInline]
class ReactionAdmin(admin.ModelAdmin): class ReactionAdmin(admin.ModelAdmin):
model = Reaction model = Reaction
list_display = ('name', 'tally', 'announcement') list_display = ('name', 'tally', 'announcement',)
search_fields = ('name', 'tally', 'announcement') search_field = ('name', 'tally', 'announcement',)
list_filter = ('name', 'tally', 'announcement')
class ReactionInline(admin.TabularInline):
model = Reaction
admin.site.register(Announcement, AnnouncementAdmin) admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Reaction, ReactionAdmin) 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 from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
...@@ -9,6 +9,7 @@ class Migration(migrations.Migration): ...@@ -9,6 +9,7 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('dashboard', '0001_initial'),
] ]
operations = [ operations = [
...@@ -17,17 +18,17 @@ class Migration(migrations.Migration): ...@@ -17,17 +18,17 @@ class Migration(migrations.Migration):
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)), ('title', models.CharField(max_length=50)),
('body', models.CharField(max_length=700)), ('body', models.TextField()),
('author', models.CharField(max_length=200)),
('pub_datetime', models.DateTimeField()), ('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
name='Reaction', name='Reaction',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)), ('name', models.CharField(choices=[('Like', 'Like'), ('Love', 'Love'), ('Angry', 'Angry')], default='Like', max_length=50)),
('tally', models.IntegerField()), ('tally', models.IntegerField(default=0)),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='announcements.announcement')), ('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.db import models
from django.urls import reverse
class Announcement(models.Model): class Announcement(models.Model):
title = models.CharField(max_length=50) title = models.CharField(max_length = 50)
body = models.CharField(max_length=700) body = models.TextField()
author = models.ForeignKey("dashboard.WidgetUser", on_delete=models.CASCADE) author = models.ForeignKey("dashboard.WidgetUser", on_delete=models.CASCADE)
pub_datetime = models.DateTimeField() pub_datetime = models.DateTimeField()
...@@ -11,8 +10,16 @@ class Announcement(models.Model): ...@@ -11,8 +10,16 @@ class Announcement(models.Model):
return self.title return self.title
class Reaction(models.Model): class Reaction(models.Model):
name = models.CharField(max_length=50) Like = 'Like'
tally = models.IntegerField() 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) announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE)
def __str__(self): def __str__(self):
......
from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Announcement, Reaction from .models import Announcement, Reaction
def index(request): def index(request):
all_announcements = Announcement.objects.all() announcements = Announcement.objects.all()
all_reactions = Reaction.objects.all() reactions = Reaction.objects.all()
response = "Big Django Energy - Announcement Board<br><br>Announcements:<br>" response = "Widget's Announcement Board<br><br>Announcements:<br>"
for announcement in all_announcements: for announcement in announcements:
announcementpubdate = announcement.pub_datetime.strftime("%m/%d/%Y, %H:%M:%S") +", " response += "{} by {} published {}:<br>{}<br>".format(
response = response + announcement.title + " by " + announcement.author.__str__() announcement.title,
response = response + " published " + announcementpubdate + "<br>" announcement.author,
response = response + announcement.body + "<br>" announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
for reaction in all_reactions: announcement.body
)
for reaction in reactions:
if reaction.announcement == announcement: if reaction.announcement == announcement:
response = response + reaction.name + ": " + str(reaction.tally) + "<br>" response += "{}: {}<br>".format(
response = response + "<br>" reaction.name,
str(reaction.tally)
)
response += "<br>"
return HttpResponse(response) return HttpResponse(response)
from django.contrib import admin from django.contrib import admin
from .models import Assignment, Course from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin): class AssignmentInline(admin.TabularInline):
model = Assignment model = Assignment
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
list_display = ('name', 'description', 'course', 'perfect_score', 'passing_score',) list_display = ('name', 'description', 'course', 'perfect_score', 'passing_score',)
search_field = ('name', 'description', 'course', 'perfect_score', 'passing_score',)
class CourseAdmin(admin.ModelAdmin): class CourseAdmin(admin.ModelAdmin):
model = Course model = Course
list_display = ('code', 'title', 'section',) list_display = ('code', 'title', 'section',)
search_field = ('code', 'title', 'section',)
inlines = [AssignmentInline]
admin.site.register(Assignment, AssignmentAdmin) admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin) 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 from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration): class Migration(migrations.Migration):
...@@ -12,23 +13,23 @@ class Migration(migrations.Migration): ...@@ -12,23 +13,23 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Assignment', name='Course',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=100, null=True)), ('code', models.CharField(max_length=10)),
('description', models.TextField(blank=True, null=True)), ('title', models.CharField(max_length=50)),
('course', models.CharField(blank=True, max_length=50, null=True)), ('section', models.CharField(max_length=3)),
('perfect_score', models.IntegerField(blank=True, null=True)),
('passing_score', models.IntegerField(blank=True, null=True)),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
name='Course', name='Assignment',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(blank=True, max_length=10, null=True)), ('name', models.CharField(max_length=50)),
('title', models.CharField(blank=True, max_length=100, null=True)), ('description', models.TextField()),
('section', models.CharField(blank=True, max_length=3, null=True)), ('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 from django.db import models
class Assignment(models.Model): class Course(models.Model):
name = models.CharField(max_length = 100, blank = True, null = True) code = models.CharField(max_length = 10)
description = models.TextField(blank = True, null = True) title = models.CharField(max_length = 50)
course = models.CharField(max_length = 50, blank = True, null = True) section = models.CharField(max_length = 3)
perfect_score = models.IntegerField(blank = True, null = True)
passing_score = models.IntegerField(blank = True, null = True)
def __str__(self): 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): def save(self, *args, **kwargs):
code = models.CharField(max_length = 10, blank = True, null = True) self.passing_score = round(self.perfect_score*0.6)
title = models.CharField(max_length = 100, blank = True, null = True) super(Assignment, self).save(*args, **kwargs)
section = models.CharField(max_length = 3, blank = True, null = True)
def __str__(self): def __str__(self):
return self.code return self.name
\ No newline at end of file \ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Assignment
from .models import Assignment, Course
def index(request): def index(request):
assignmentlist = Assignment.objects.all() assignments = Assignment.objects.all()
courselist = Course.objects.all()
response = "Widget's Assignment Page"
i = 0 response = "Widget's Assignment Page<br><br>"
while i < len(assignmentlist): for assignment in assignments:
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}" response += "Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {}<br><br>".format(
i+=1 assignment.name,
assignment.description,
assignment.perfect_score,
assignment.passing_score,
assignment.course
)
return HttpResponse(response) return HttpResponse(response)
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
from .models import Event, Location from .models import Event, Location
# Register your models here. class EventInline(admin.TabularInline):
model = Event
class EventAdmin(admin.ModelAdmin): class EventAdmin(admin.ModelAdmin):
model = Event model = Event
list_display = ("target_datetime", "activity", "estimated_hours", "locations", "course",) list_display = ("target_datetime", "activity", "estimated_hours", "locations", "course",)
search_field = ("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): class LocationAdmin(admin.ModelAdmin):
model = Location model = Location
list_display = ("modes", "venue",) list_display = ("modes", "venue",)
search_field = ("modes", "venue",) search_field = ("modes", "venue",)
list_filter = ("venue",) inlines = [EventInline]
admin.site.register(Event, EventAdmin) admin.site.register(Event, EventAdmin)
admin.site.register(Location, LocationAdmin) 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 from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
...@@ -9,25 +9,27 @@ class Migration(migrations.Migration): ...@@ -9,25 +9,27 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('assignments', '0001_initial'),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Event', name='Location',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('target_datetime', models.DateTimeField(verbose_name='Target Date & Time')), ('modes', models.CharField(choices=[('Onsite', 'Onsite'), ('Online', 'Online'), ('Hybrid', 'Hybrid')], default='Onsite', max_length=50)),
('activity', models.CharField(max_length=300)), ('venue', models.CharField(max_length=50)),
('estimated_hours', models.FloatField(default=0)),
('locations', models.CharField(max_length=300)),
('course', models.CharField(max_length=300)),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
name='Location', name='Event',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('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 from django.db import models
# Create your models here.
class Location(models.Model): class Location(models.Model):
Onsite = 'onsite' Onsite = 'Onsite'
Online = 'online' Online = 'Online'
Hybrid = 'Hybrid'
mode_options = [ mode_options = [
(Onsite, 'onsite'), (Onsite, 'Onsite'),
(Online, 'online'), (Online, 'Online'),
(Hybrid, 'Hybrid'),
] ]
modes = models.CharField(max_length=150, choices=mode_options, default=Onsite) modes = models.CharField(max_length = 50, choices=mode_options, default=Onsite)
venue = models.CharField(max_length=150) venue = models.CharField(max_length = 50)
def __str__(self): def __str__(self):
return self.venue return self.venue
class Event(models.Model): class Event(models.Model):
target_datetime = models.DateTimeField("Target Date & Time") target_datetime = models.DateTimeField()
activity = models.CharField(max_length=300) activity = models.CharField(max_length = 50)
estimated_hours = models.FloatField(default=0) estimated_hours = models.FloatField(default=0)
locations = models.ForeignKey(Location, on_delete=models.CASCADE) 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): def __str__(self):
return self.activity return self.activity
\ No newline at end of file
# models.ForeignKeys('assignments.Course', on_delete=models.CASCADE)
...@@ -2,5 +2,5 @@ from django.urls import path ...@@ -2,5 +2,5 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.calendarschedule, name = "calendarschedule") path('', views.index, name = "index")
] ]
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Event from .models import Event
# Create your views here. def index(request):
def calendarschedule(request): events = Event.objects.all()
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>"
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) return HttpResponse(response)
\ No newline at end of file
from django.contrib import admin 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): class DepartmentAdmin(admin.ModelAdmin):
model = department model = Department
search_fields = ('dept_name', 'home_unit')
list_display = ('dept_name', 'home_unit') list_display = ('dept_name', 'home_unit')
list_filter = ('dept_name', 'home_unit') search_field = ('dept_name', 'home_unit')
inlines = [WidgetUserInline]
class widgetUsersAdmin(admin.ModelAdmin): class WidgetUsersAdmin(admin.ModelAdmin):
model = widgetUser model = WidgetUser
search_fields = ('first_name', 'middle_name', 'last_name', 'department') list_display = ('first_name', 'middle_name', 'last_name', 'department')
list_display = ('first_name', 'last_name', 'department') search_field = ('first_name', 'middle_name', 'last_name', 'department')
list_filter = ('first_name', 'last_name', 'department')
admin.site.register(department, departmentAdmin) admin.site.register(Department, DepartmentAdmin)
admin.site.register(widgetUser, widgetUsersAdmin) admin.site.register(WidgetUser, WidgetUsersAdmin)
\ No newline at end of file \ 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 from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
...@@ -13,20 +13,20 @@ class Migration(migrations.Migration): ...@@ -13,20 +13,20 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='department', name='Department',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('dept_name', models.CharField(max_length=100)), ('dept_name', models.CharField(max_length=50)),
('home_unit', models.CharField(max_length=100)), ('home_unit', models.CharField(max_length=50)),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
name='widgetUser', name='WidgetUser',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=100)), ('first_name', models.CharField(max_length=50)),
('middle_name', models.CharField(max_length=100)), ('middle_name', models.CharField(max_length=50)),
('last_name', models.CharField(max_length=100)), ('last_name', models.CharField(max_length=50)),
('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.department')), ('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.department')),
], ],
), ),
......
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
class department(models.Model): class Department(models.Model):
dept_name = models.CharField(max_length = 100) dept_name = models.CharField(max_length = 50)
home_unit = models.CharField(max_length = 100, ) home_unit = models.CharField(max_length = 50)
def __str__(self): def __str__(self):
return '{}'.format(self.dept_name) return self.dept_name
def get_absolute_url(self): class WidgetUser(models.Model):
return reverse('department', args= [str(self.dept_name)]) first_name = models.CharField(max_length = 50)
middle_name = models.CharField(max_length = 50)
class widgetUser(models.Model): last_name = models.CharField(max_length = 50)
first_name = models.CharField(max_length = 100) department = models.ForeignKey(Department, on_delete = models.CASCADE)
middle_name = models.CharField(max_length = 100)
last_name = models.CharField(max_length = 100)
department = models.ForeignKey(
department,
on_delete = models.CASCADE,)
def __str__(self): def __str__(self):
return '{} {}'.format(self.first_name, self.last_name) return '{} {}'.format(self.first_name, self.last_name)
\ No newline at end of file
def get_absolute_url(self):
return reverse('widgetUser', args= [str(self.last_name)])
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import department, widgetUser from .models import Department, WidgetUser
def dashboard(request): def dashboard(request):
welcome_message = "Welcome to Widget!<br><br>WIDGET USERS:<br>" widgetusers = WidgetUser.objects.all()
all_widgetUser = widgetUser.objects.all()
for member in all_widgetUser: response = "Welcome to Widget!<br><br>WIDGET USERS:<br>"
last_name = member.last_name for user in widgetusers:
first_name = member.first_name response += "{}, {} {}: {}, {}<br>".format(
middle_name = member.middle_name user.last_name,
dept_name = member.department.dept_name user.first_name,
home_unit = member.department.home_unit user.middle_name,
output = "{lastName}, {firstName} {middleName}: {deptName}, {homeUnit}<br>".format(lastName = last_name, firstName = first_name, middleName = middle_name, deptName = dept_name, homeUnit = home_unit) user.department,
welcome_message += output user.department.home_unit
)
return HttpResponse(welcome_message) return HttpResponse(response)
\ No newline at end of file \ No newline at end of file
from django.contrib import admin 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')),
],
),
]
from django.db import models from django.db import models
# Create your models here. class ForumPost(models.Model):
title = models.CharField(max_length = 50)
body = models.TextField()
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
def __str__(self):
return self.title
class Reply(models.Model):
body = models.TextField()
author = models.ForeignKey('dashboard.WidgetUser', on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
def __str__(self):
return self.body
from django.urls import path
from . import views
urlpatterns = [
path('', views.forum, name="forum")
]
\ No newline at end of file
from django.shortcuts import render from django.http import HttpResponse
from .models import ForumPost, Reply
# Create your views here. def forum(request):
forumposts = ForumPost.objects.all()
replies = Reply.objects.all()
response = "Widget's Forum<br><br>Forum Posts:<br>"
for post in forumposts:
response += "{} by {} posted {}:<br>{}<br>".format(
post.title,
post.author,
post.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
post.body
)
for reply in replies:
response += "Reply by {} posted {}:<br>{}<br>".format(
reply.author,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
reply.body
)
return HttpResponse(response)
...@@ -31,6 +31,11 @@ ALLOWED_HOSTS = [] ...@@ -31,6 +31,11 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'dashboard.apps.DashboardConfig',
'announcements.apps.AnnouncementsConfig',
'forum.apps.ForumConfig',
'assignments.apps.AssignmentsConfig',
'calendars.apps.CalendarsConfig',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
......
...@@ -14,8 +14,13 @@ Including another URLconf ...@@ -14,8 +14,13 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('dashboard/', include("dashboard.urls")),
path('announcements/', include("announcements.urls")),
path('forum/', include("forum.urls")),
path('assignments/', include("assignments.urls")),
path('calendar/', include("calendars.urls")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
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