Commit 31836b43 authored by Franco Velasco's avatar Franco Velasco

Merge branch 'velasco/homepage' into 'master'

Created Department Model, Linked Models to View

See merge request !7
parents 95715cd4 9f5c0b77
from django.contrib import admin
from .models import WidgetUser
from .models import WidgetUser, Department
# Register your models here.
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
list_display = ('first_name', 'last_name',)
search_fields = ('last_name', 'first_name')
list_display = ('last_name', 'first_name',)
filter = ('department', )
class DepartmentAdmin(admin.ModelAdmin):
model = Department
list_display = ('dept_name',)
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Department, DepartmentAdmin)
from django.db import models
# Create your models here.
"""
A model for a school department in Widget.
Has fields for the names of the department and the unit it is associated with.
"""
class Department(models.Model):
dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=50)
def __str__(self):
return f"{self.dept_name}, {self.home_unit}"
"""
A model for users of Widget.
Asks for firstname, middle name, last name, ID number, and Email.
"""
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)
id_num = models.IntegerField()
email = models.EmailField()
department = models.ForeignKey(Department, on_delete=models.CASCADE)
def __str__(self):
return f"{self.last_name}, {self.first_name} {self.middle_name}"
return f"""{self.last_name}, {self.first_name} {self.middle_name}:
{self.id_num}, {self.email}, {self.department}"""
from django.shortcuts import render
from django.http import HttpResponse
from .models import WidgetUser
def index(response):
userString = "WIDGET USERS:<br>"
users = WidgetUser.objects.all()
for user in users:
userString += f"""{user}<br>"""
return HttpResponse(
'<span style="color: #365f90; font-size: xx-large; font-weight: bold; font-family: helvetica"> Welcome to Widget! </span>'
userString
)
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