Commit bb857699 authored by Andre Matthew Dumandan's avatar Andre Matthew Dumandan 😴

Merge branch 'dumandan/homepage' into 'master'

Created Department model in Homepage app, Added id_number and email field in WidgetUser model in Homepage app, Edited the HttpResponse views.py of Homepage app.
parents 783695f2 cbd1b286
from django.contrib import admin
from .models import WidgetUser
from .models import WidgetUser,Department
# Register your models here.
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
search_fields = ('first_name','last_name')
list_display = ('first_name','middle_name','last_name')
list_display = ('first_name','middle_name','last_name','id_num','email','department')
list_filter = ('last_name', 'first_name')
class DepartmentAdmin(admin.ModelAdmin):
model = Department
list_display = ('dept_name','home_unit')
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Department,DepartmentAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-03-21 09:09
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
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=124)),
('home_unit', models.CharField(max_length=124)),
],
),
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=35)),
('middle_name', models.CharField(max_length=20)),
('last_name', models.CharField(max_length=20)),
('id_num', models.IntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(9999999)])),
('email', models.EmailField(max_length=254)),
('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.department')),
],
),
]
# Generated by Django 4.0.3 on 2022-03-21 09:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='id_num',
field=models.IntegerField(),
),
]
# Generated by Django 4.0.3 on 2022-03-21 09:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_alter_widgetuser_id_num'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='email',
field=models.EmailField(default='', max_length=254),
),
migrations.AlterField(
model_name='widgetuser',
name='id_num',
field=models.IntegerField(default=''),
),
]
# Generated by Django 4.0.3 on 2022-03-21 09:21
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0003_alter_widgetuser_email_alter_widgetuser_id_num'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='id_num',
field=models.IntegerField(default='', validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(9999999)]),
),
]
# Generated by Django 4.0.3 on 2022-03-23 07:38
from django.db import migrations, models
import homepage.models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0004_alter_widgetuser_id_num'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='id_num',
field=models.CharField(default='', max_length=7, validators=[homepage.models.WidgetUser.ID_validator]),
),
]
from xml.dom import ValidationErr
from django.db import models
from django.core.exceptions import ValidationError
# Create your models here.
class Department(models.Model):
dept_name = models.CharField(max_length=124)
home_unit = models.CharField(max_length=124)
def __str__(self):
return '{}'.format(self.dept_name)
def get_dept_info(self):
return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model):
first_name = models.CharField(max_length=35)
middle_name = models.CharField(max_length=20)
last_name= models.CharField(max_length=20)
def ID_validator(value):
if value.isdigit() != True:
raise ValidationError('Student ID must be Integers')
first_name = models.CharField(max_length=35,default='')
middle_name = models.CharField(max_length=20,default='')
last_name = models.CharField(max_length=20,default='')
id_num = models.CharField(max_length=7,default='',validators=[ID_validator])
email = models.EmailField(default='')
department = models.ForeignKey(Department,on_delete=models.CASCADE,default='')
def __str__(self):
return 'Name: {}, {} {}'.format(self.last_name, self.first_name, self.last_name)
\ No newline at end of file
return '{}, {} {}'.format(self.last_name, self.first_name, self.middle_name)
def get_user_info(self):
return '{}, {} {}: {}, {}, {} </br>'.format(
self.last_name,self.first_name,
self.middle_name,self.id_num,self.email,
self.department.get_dept_info()
)
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import WidgetUser
# Create your views here.
def index(request):
return HttpResponse('Welcome to the Widget!')
\ No newline at end of file
model = WidgetUser
widget_users = model.objects.all()
homepage_response = "WIDGET USERS: </br>"
for user in widget_users:
homepage_response += user.get_user_info()
return HttpResponse(homepage_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