mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2025-06-28 16:25:44 +08:00
Autocreate superuser from .env file as well as autogenerate year level and course records
This commit is contained in:
parent
48f6bee125
commit
ceba84acb5
16 changed files with 174 additions and 4 deletions
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-27 07:31
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('courses', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='course',
|
||||
old_name='course_name',
|
||||
new_name='name',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='course',
|
||||
old_name='course_shortname',
|
||||
new_name='shortname',
|
||||
),
|
||||
]
|
|
@ -1,10 +1,26 @@
|
|||
from django.db import models
|
||||
from django.db.models.signals import post_migrate
|
||||
from django.dispatch import receiver
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Course(models.Model):
|
||||
course_name = models.CharField(max_length=64)
|
||||
course_shortname = models.CharField(max_length=16)
|
||||
name = models.CharField(max_length=64)
|
||||
shortname = models.CharField(max_length=16)
|
||||
|
||||
def __str__(self):
|
||||
return self.course_shortname
|
||||
return self.shortname
|
||||
|
||||
|
||||
@receiver(post_migrate)
|
||||
def populate_courses(sender, **kwargs):
|
||||
if sender.name == 'courses':
|
||||
Course.objects.get_or_create(
|
||||
name='Bachelor of Science in Information Technology', shortname='BSIT')
|
||||
Course.objects.get_or_create(
|
||||
name='Bachelor of Science in Computer Science', shortname='BSCS')
|
||||
Course.objects.get_or_create(
|
||||
name='Bachelor of Science in Computer Engineering ', shortname='BSCpE')
|
||||
Course.objects.get_or_create(
|
||||
name='Bachelor of Science in Data Science', shortname='BSDS')
|
||||
# Add more predefined records as needed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue