Commit f249f755 authored by justin's avatar justin

Added basic admin functionality and fixed views in dashboard

parent 9b8480f2
from django.contrib import admin
from .models import Department, WidgetUser
# Register your models here.
class DepartmentAdmin(admin.ModelAdmin):
model = Department
list_display = (
"dept_name",
"home_unit",
)
search_fields = (
"dept_name",
"home_unit",
)
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
list_display = (
"last_name",
"first_name",
"middle_name",
"department",
)
search_fields = (
"first_name",
"middle_name",
"last_name",
"department",
)
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Department, DepartmentAdmin)
from django.db import models
from django.http import HttpResponse
from .models import Department, WidgetUser
class Department(models.Model):
dept_name = models.CharField(max_length=255)
home_unit = models.CharField(max_length=255)
def dashboard(request):
content = "Welcome to Widget! <br><br> WIDGET USERS: <br>"
users = WidgetUser.objects.all()
def __str__(self):
return f"{self.dept_name}, {self.home_unit}"
for user in users:
content += str(user) + ": " + str(user.department) + "<br>"
class WidgetUser(models.Model):
first_name = models.CharField(max_length=255)
middle_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
department = models.ForeignKey(
Department,
on_delete=models.CASCADE,
)
def __str__(self):
return f"{self.last_name}, {self.first_name} {self.middle_name}"
def displayName(self):
return f"{self.first_name} {self.last_name}"
return HttpResponse(content)
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