Commit c07c16ae authored by Joseph Izon's avatar Joseph Izon 💀

Merge branch 'izon/homepage'

parents 39ad5007 0191f2d7
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import WidgetUser from .models import Department, WidgetUser
class WidgetUserAdmin(admin.ModelAdmin): class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser model = WidgetUser
search_fields = ('first_name', 'last_name',) 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',) 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(WidgetUser, WidgetUserAdmin)
admin.site.register(Department, DepartmentAdmin)
...@@ -6,6 +6,24 @@ class WidgetUser(models.Model): ...@@ -6,6 +6,24 @@ class WidgetUser(models.Model):
first_name = models.CharField(max_length=50) first_name = models.CharField(max_length=50)
middle_name = models.CharField(max_length=50) middle_name = models.CharField(max_length=50)
last_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): def __str__(self):
return self.last_name return self.last_name
\ No newline at end of file
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 django.http import HttpResponse
from homepage.models import WidgetUser
from homepage.models import Department
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("Welcome to the Widget's Home Page!") widgetuser_objects = WidgetUser.objects.all()
\ No newline at end of file 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