Commit 483b128b authored by Charles Lim's avatar Charles Lim

Added extra fields to WidgetUser model. Also added new department model to...

Added extra fields to WidgetUser model. Also added new department model to homepage application. Also added homepage template html file and corresponding view.
parent 1455e4f7
from django.contrib import admin
from .models import WidgetUser
from .models import Department, WidgetUser
# Widget User Model
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
admin.site.register(WidgetUser, WidgetUserAdmin)
\ No newline at end of file
# Department Model
class DepartmentAdmin(admin.ModelAdmin):
model = Department
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Department, DepartmentAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-01 10:47
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
]
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=100)),
('home_unit', models.CharField(max_length=100)),
],
),
migrations.AddField(
model_name='widgetuser',
name='email',
field=models.EmailField(default='none', max_length=256),
),
migrations.AddField(
model_name='widgetuser',
name='id_num',
field=models.CharField(default='none', max_length=7),
),
migrations.AddField(
model_name='widgetuser',
name='department',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='homepage.department'),
),
]
from django.db import models
# Model for homepage application
# Model for Department
class Department(models.Model):
dept_name = models.CharField(max_length=100)
home_unit = models.CharField(max_length=100)
# Model for Widget User
class WidgetUser(models.Model):
first_name = models.CharField(max_length=100)
middle_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
\ No newline at end of file
last_name = models.CharField(max_length=100)
id_num = models.CharField(max_length=7, default="123456")
email = models.EmailField(max_length=256, default="john.appleseed@gmail.com")
department = models.ForeignKey(
Department,
on_delete=models.SET_NULL,
null=True
)
<html>
<head>
<title>Homepage</title>
</head>
WIDGET USERS: <br>
{% for user in all_widgetusers %}
{{user.last_name}}, {{user.first_name}} {{user.middle_name}}: {{user.id_num}},
{{user.department.dept_name}}, {{user.department.home_unit}} </br>
{% endfor %}
</body>
</html>
\ No newline at end of file
from django.urls import path
from .views import index
from .views import homepage_view
urlpatterns = [
path('', index, name='index'),
path('', homepage_view, name='homepage_view'),
]
app_name = "homepage"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import WidgetUser
# View for HomePage
def index(request):
return HttpResponse("Welcome to Widget!")
def homepage_view(request):
objects_set = {
"all_widgetusers": [obj for obj in WidgetUser.objects.all()]
}
print(objects_set["all_widgetusers"][0].__dict__)
return render(request, "homepage_template.html", objects_set)
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