Commit 0191f2d7 authored by Joseph Izon's avatar Joseph Izon 💀

Created the Department Model and Added the id_num and email field in the existing WidgerUser model

parent 4af4f941
No preview for this file type
from django.contrib import admin
# Register your models here.
from .models import WidgetUser
from .models import Department, WidgetUser
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
search_fields = ('first_name', 'last_name',)
list_display = ('first_name', 'middle_name', 'last_name',)
list_display = ('id_num','first_name', 'middle_name', 'last_name',)
list_filter = ('first_name', 'middle_name', 'last_name',)
class DepartmentAdmin(admin.ModelAdmin):
model = Department
search_fields = ('dept_name', 'home_unit',)
list_display = ('dept_name', 'home_unit',)
list_filter = ('dept_name', 'home_unit',)
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Department, DepartmentAdmin)
......@@ -6,6 +6,24 @@ 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.CharField(max_length=7)
email = models.EmailField(max_length=100)
def __str__(self):
return self.last_name
\ No newline at end of file
return self.last_name
class Department(models.Model):
#Two Parameters (Model to which the Association is being made, process that you want to be done when a particular model is deleted)
user = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=50)
#so that when calling the objects of the department, the title would be displayed instead of a number
def __str__(self):
return self.dept_name
from urllib import response
from django.http import HttpResponse
from homepage.models import WidgetUser
from homepage.models import Department
# Create your views here.
def index(request):
return HttpResponse("Welcome to the Widget's Home Page!")
\ No newline at end of file
widgetuser_objects = WidgetUser.objects.all()
department_objects = Department.objects.all()
title = "Welcome to the Widget's Home Page!<br><br>"
response = "WIDGET USERS:<br>"
for dept in department_objects:
response = (response + f"{dept.user.last_name}, {dept.user.first_name} {dept.user.middle_name}: "
+ f"{dept.user.id_num}, {dept.user.email}, "
+ f"{dept.dept_name}, {dept.home_unit}<br>"
)
return HttpResponse(title + response)
\ No newline at end of file
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