Commit 4b934cfd authored by Jonathan Talbot's avatar Jonathan Talbot

working midterm

parent 88d787c1
No preview for this file type
......@@ -4,8 +4,8 @@ from .models import WidgetUser, Forum, Announcement, Assignment, Department
# Classes
class DepartmentInline(admin.TabularInline):
model = Department
class WidgetUserInline(admin.TabularInline):
model = WidgetUser
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
......@@ -26,11 +26,25 @@ class WidgetUserAdmin(admin.ModelAdmin):
}),
]
inlines = [DepartmentInline,]
class DepartmentAdmin(admin.ModelAdmin):
model = Department
search_fields = ('dept_name', 'home_unit')
list_display = ('dept_name', 'home_unit')
list_filter = ('dept_name', 'home_unit')
fieldsets = [
('Department Data', {
'fields': [
'dept_name',
'home_unit',
]
}),
]
inlines = [WidgetUserInline,]
class AnnouncementAdmin(admin.ModelAdmin):
model = Announcement
......@@ -100,3 +114,4 @@ admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Forum, ForumAdmin)
admin.site.register(Announcement, AnnouncementAdmin)
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Department, DepartmentAdmin)
# Generated by Django 4.0.3 on 2022-04-07 06:21
# Generated by Django 4.0.3 on 2022-04-07 22:37
from django.db import migrations, models
import django.db.models.deletion
......@@ -30,6 +30,14 @@ class Migration(migrations.Migration):
('max_points', models.IntegerField()),
],
),
migrations.CreateModel(
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)),
],
),
migrations.CreateModel(
name='Forum',
fields=[
......@@ -48,15 +56,7 @@ class Migration(migrations.Migration):
('middle_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
('email', models.EmailField(max_length=254)),
],
),
migrations.CreateModel(
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)),
('widget_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='widget_group3.widgetuser')),
('department', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='widget_group3.department')),
],
),
]
# Generated by Django 4.0.3 on 2022-04-08 03:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('widget_group3', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='first_name',
field=models.CharField(max_length=90),
),
]
from django.db import models
from django.urls import reverse
# Department used for widget user
class Department(models.Model):
dept_name = models.CharField(max_length=100)
home_unit = models.CharField(max_length=100)
def __str__(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model):
id_num = models.IntegerField()
first_name = models.CharField(max_length=100)
first_name = models.CharField(max_length=90)
middle_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email = models.EmailField()
def __str__(self):
return '{}, {} {}: {}, {}'.format(self.last_name, self.first_name, self.middle_name, self.id_num, self.email)
department = models.ForeignKey(Department, on_delete=models.CASCADE, default=1)
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)
# Department used for widget user
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)
return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name)
class Announcement(models.Model):
......
......@@ -3,7 +3,15 @@ from .models import WidgetUser, Forum, Announcement, Assignment, Department
def homepage(request):
widget_users = WidgetUser.objects.all()
output = "WIDGET USERS:\n" + "\n".join([str(user) for user in widget_users])
departments = Department.objects.all()
output = "WIDGET USERS:\n" + "\n".join(
['{}: {}, {}, {}'.format(str(user.full_name),
str(user.id_num),
str(user.email),
str(user.department))
for user in widget_users]
)
return HttpResponse(output, content_type="text/plain")
def assignments(request):
......
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