updated models and added to views

parent a665ee4c
...@@ -3,6 +3,10 @@ from django.contrib import admin ...@@ -3,6 +3,10 @@ from django.contrib import admin
from .models import * from .models import *
# Register your models here. # Register your models here.
class WidgetUserAdmin(admin.ModelAdmin): class WidgetUserAdmin(admin.ModelAdmin):
list_display=("first_name", "middle_name", "last_name") list_display=("first_name", "middle_name", "last_name", "id_num", "email", "department")
class DepartmentAdmin(admin.ModelAdmin):
list_display=("dept_name", "home_unit")
admin.site.register(WidgetUser,WidgetUserAdmin) admin.site.register(WidgetUser,WidgetUserAdmin)
admin.site.register(Department,DepartmentAdmin)
# Generated by Django 4.0.3 on 2022-04-05 03:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='email',
field=models.CharField(default='', max_length=100),
),
migrations.AddField(
model_name='widgetuser',
name='id_num',
field=models.CharField(default='', max_length=7),
),
]
# Generated by Django 4.0.3 on 2022-04-05 03:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_widgetuser_email_widgetuser_id_num'),
]
operations = [
migrations.CreateModel(
name='Department',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('dept_name', models.CharField(max_length=50)),
('home_unit', models.CharField(max_length=50)),
],
),
]
# Generated by Django 4.0.3 on 2022-04-05 03:16
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0003_department'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='department',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.department'),
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Department(models.Model):
dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=50)
class WidgetUser(models.Model): class WidgetUser(models.Model):
first_name = models.CharField(max_length=50, default="A") first_name = models.CharField(max_length=50, default="A")
middle_name = models.CharField(max_length=50, default="B") middle_name = models.CharField(max_length=50, default="B")
last_name = models.CharField(max_length=50, default="C") last_name = models.CharField(max_length=50, default="C")
id_num = models.CharField(max_length=7, default = "")
email = models.CharField(max_length=100, default = "")
department = models.ForeignKey(Department, on_delete = models.CASCADE, null=True)
from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Department, WidgetUser
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("Welcome to Widget!")
\ No newline at end of file message = 'WIDGET USERS:<br/>'
depts = Department.objects.all()
for d in depts:
widget_users = WidgetUser.objects.filter(department=d)
for w in widget_users:
message += f"{w.last_name}, {w.first_name} {w.middle_name}: {w.id_num}, {w.email}, {d.dept_name}, {d.home_unit}<br/>"
return HttpResponse(message)
\ 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