Commit ac1866a1 authored by Teo Quinto's avatar Teo Quinto

Added Department model and new fields to WidgetUser model. Added new entries thru Django Admin.

parent cfe49dca
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Department
from .models import WidgetUser from .models import WidgetUser
class DepartmentAdmin(admin.ModelAdmin):
model = Department
class WidgetUserAdmin(admin.ModelAdmin): class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser model = WidgetUser
admin.site.register(Department)
admin.site.register(WidgetUser) admin.site.register(WidgetUser)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-05 08:35
from django.db import migrations, models
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=40)),
('home_unit', models.CharField(max_length=40)),
],
),
]
# Generated by Django 4.0.3 on 2022-04-05 09:27
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_department'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='department',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.department'),
),
migrations.AddField(
model_name='widgetuser',
name='email',
field=models.EmailField(default='email@address.com', max_length=320),
),
migrations.AddField(
model_name='widgetuser',
name='id_num',
field=models.IntegerField(default=1, validators=[django.core.validators.MaxValueValidator(9999999)]),
),
]
from django.db import models from django.db import models
from django.core.validators import MaxValueValidator
DEFAULT_DEPARTMENT_ID = 1
DEFAULT_ID_NUM = 1
# Create your models here. # Create your models here.
class Department(models.Model):
dept_name = models.CharField(max_length=40)
home_unit = models.CharField(max_length=40)
def __str__(self):
return '{}'.format(self.dept_name)
class WidgetUser(models.Model): class WidgetUser(models.Model):
first_name = models.CharField(max_length=15) first_name = models.CharField(max_length=15)
middle_name = models.CharField(max_length=15) middle_name = models.CharField(max_length=15)
last_name = models.CharField(max_length=15) last_name = models.CharField(max_length=15)
id_num = models.IntegerField(default=DEFAULT_ID_NUM, validators=[MaxValueValidator(9999999)])
email = models.EmailField(max_length=320, default="email@address.com")
department = models.ForeignKey(Department, on_delete=models.CASCADE, default=DEFAULT_DEPARTMENT_ID)
def __str__(self): def __str__(self):
return '{} {}'.format(self.first_name, self.last_name) return '{} {}'.format(self.first_name, self.last_name)
\ 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