2023-06-27 15:41:34 +08:00
|
|
|
from django.db.models.signals import post_migrate
|
|
|
|
from django.dispatch import receiver
|
2023-06-27 18:15:31 +08:00
|
|
|
from django.db import models
|
2023-06-27 14:16:40 +08:00
|
|
|
# Create your models here.
|
|
|
|
|
|
|
|
|
|
|
|
class Course(models.Model):
|
2023-06-27 15:41:34 +08:00
|
|
|
name = models.CharField(max_length=64)
|
|
|
|
shortname = models.CharField(max_length=16)
|
2023-06-27 18:15:31 +08:00
|
|
|
subjects = models.ManyToManyField(
|
|
|
|
'subjects.Subject', related_name='SubjectCourse_course', through='courses.SubjectCourse')
|
2023-06-27 14:16:40 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
2023-06-27 15:48:43 +08:00
|
|
|
return self.name
|
2023-06-27 15:41:34 +08:00
|
|
|
|
|
|
|
|
2023-06-27 18:15:31 +08:00
|
|
|
class SubjectCourse(models.Model):
|
|
|
|
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
|
|
|
course = models.ForeignKey(
|
|
|
|
'courses.Course', on_delete=models.CASCADE, null=True)
|
|
|
|
|
2023-07-10 17:20:15 +08:00
|
|
|
def __str__(self):
|
|
|
|
return (self.subject + ' under course ' + self.course)
|
|
|
|
|
2023-06-27 18:15:31 +08:00
|
|
|
|
2023-06-27 15:41:34 +08:00
|
|
|
@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
|