StudE-Backend/stude/semesters/models.py

24 lines
653 B
Python
Raw Permalink Normal View History

2023-06-27 15:48:43 +08:00
from django.db import models
from django.db.models.signals import post_migrate
from django.dispatch import receiver
# Create your models here.
class Semester(models.Model):
name = models.CharField(max_length=64)
shortname = models.CharField(max_length=16)
def __str__(self):
return self.name
@receiver(post_migrate)
2023-06-27 18:15:31 +08:00
def populate_semesters(sender, **kwargs):
2023-06-27 15:48:43 +08:00
if sender.name == 'semesters':
Semester.objects.get_or_create(
2023-06-27 18:15:31 +08:00
name='1st Semester', shortname='1stSem')
2023-06-27 15:48:43 +08:00
Semester.objects.get_or_create(
2023-06-27 18:15:31 +08:00
name='2nd Semester', shortname='2ndSem')
2023-06-27 15:48:43 +08:00
# Add more predefined records as needed