Commit 44b68c5a authored by Justin Daniel Mendoza's avatar Justin Daniel Mendoza

Updated Models.py and Views.py for HomePage

parent 27e6b7bb
No preview for this file type
...@@ -2,5 +2,7 @@ from django.contrib import admin ...@@ -2,5 +2,7 @@ from django.contrib import admin
# Register your models here. # Register your models here.
from .models import WidgetUser from .models import WidgetUser
from .models import Department
admin.site.register(WidgetUser) admin.site.register(WidgetUser)
admin.site.register(Department)
# Generated by Django 4.0.3 on 2022-03-30 07:02
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='email',
field=models.EmailField(default=1, max_length=100),
preserve_default=False,
),
migrations.AddField(
model_name='widgetuser',
name='id_num',
field=models.IntegerField(default=1234),
preserve_default=False,
),
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)),
('widgetuser', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
],
),
]
from itertools import chain
from django.db import models from django.db import models
# Create your models here. # Create your models here.
...@@ -5,5 +6,18 @@ class WidgetUser(models.Model): ...@@ -5,5 +6,18 @@ class WidgetUser(models.Model):
first_name = models.CharField(max_length=20) first_name = models.CharField(max_length=20)
middle_name = models.CharField(max_length=10) middle_name = models.CharField(max_length=10)
last_name = models.CharField(max_length=20) last_name = models.CharField(max_length=20)
id_num = models.IntegerField()
email = models.EmailField(max_length=100)
def __str__(self):
return self.last_name + ", " + self.first_name + " " + self.middle_name + ": " + str(self.id_num) + ", " + self.email + "<br>"
class Department(models.Model):
widgetuser = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=50)
def __str__(self):
return self.widgetuser.last_name + ", " + self.widgetuser.first_name + " " + self.widgetuser.middle_name + ": " + str(self.widgetuser.id_num) + ", " + self.widgetuser.email + ", " + self.dept_name + ", " + self.home_unit + "<br>"
\ No newline at end of file
from itertools import chain
from django.http import HttpResponse from django.http import HttpResponse
from .models import WidgetUser
from .models import Department
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("Welcome to Widget!") display0 = "WIDGET USERS: <br>"
display1 = list(display0)
display2 = Department.objects.all()
finalDisplay = chain(display1,display2)
return HttpResponse(finalDisplay)
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