Commit bfae439d authored by Cheska Hung's avatar Cheska Hung

completed

parent 5e07dfd3
from django.contrib import admin from django.contrib import admin
from .models import Department from .models import Department, WidgetUser
class DepartmentAdmin(admin.ModelAdmin): class DepartmentAdmin(admin.ModelAdmin):
...@@ -11,4 +11,9 @@ class DepartmentAdmin(admin.ModelAdmin): ...@@ -11,4 +11,9 @@ class DepartmentAdmin(admin.ModelAdmin):
search_fields = ('dept_name', 'home_unit') search_fields = ('dept_name', 'home_unit')
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
admin.site.register(Department, DepartmentAdmin) admin.site.register(Department, DepartmentAdmin)
admin.site.register(WidgetUser, WidgetUserAdmin)
# Generated by Django 4.1.6 on 2023-03-04 16:34
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Dashboard', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=50)),
('middle_name', models.CharField(max_length=50)),
('last_name', models.CharField(max_length=50)),
('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Dashboard.department')),
],
),
]
...@@ -4,3 +4,10 @@ from django.db import models ...@@ -4,3 +4,10 @@ from django.db import models
class Department(models.Model): class Department(models.Model):
dept_name = models.CharField(max_length=50) dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=100) home_unit = models.CharField(max_length=100)
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)
department = models.ForeignKey(Department, on_delete=models.CASCADE)
\ No newline at end of file
<!DOCTYPE HTML>
<HTML>
<Head>
<h1>Welcome to Widget!</h1>
</Head>
<h2>WIDGET USERS</h2>
<ul>
{% for Department in object_list %}
<li>{{Department.dept_name}}, {{Department.home_unit}}</li>
{% endfor %}
</ul>
</HTML>
from django.urls import path from django.urls import path
from .views import DashboardView from .views import Dashboard_list_view
urlpatterns = [ urlpatterns = [
path('', DashboardView.as_view()), path('', Dashboard_list_view, name='Dashboard_list_view'),
] ]
app_name = "Dashboard" app_name = "Dashboard"
\ No newline at end of file
from .models import Department from .models import WidgetUser, Department
from django.views import generic from django.http import HttpResponse
from django.shortcuts import render
class DashboardView(generic.ListView): def Dashboard_list_view(request):
model = Department html_string_1 = '<html lang="en"><head><meta charset="UTF-8">' \
template_name = 'Dashboard/Dashboard.html' '<h1>Welcome to Widget</h1>' \
'<h2>WIDGET USERS</h2></head><ul>'
html_string_2 = ''
for wu in WidgetUser.objects.all():
html_string_2 += '<li>{}, {} {}: {}, {}' .format(wu.last_name,
wu.first_name,
wu.middle_name,
wu.department.dept_name,
wu.department.home_unit)
html_string_2 += '</ul></li>'
html_string_final = html_string_1 + html_string_2 + '</html>'
return HttpResponse(html_string_final)
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