2023-04-22 11:00:04 +08:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.timezone import now
|
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
|
|
|
|
|
|
|
|
class Schedule(models.Model):
|
2023-04-22 14:14:53 +08:00
|
|
|
name = models.TextField()
|
2023-04-22 11:00:04 +08:00
|
|
|
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
2023-04-22 15:31:58 +08:00
|
|
|
year_level = models.TextField()
|
|
|
|
|
2023-04-22 11:00:04 +08:00
|
|
|
students_assigned = models.ManyToManyField(
|
|
|
|
'students.Student', related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule')
|
|
|
|
professor = models.OneToOneField(
|
|
|
|
'professors.Professor', related_name='Professor_full_name', on_delete=models.CASCADE)
|
2023-04-22 15:31:58 +08:00
|
|
|
|
2023-04-22 14:38:27 +08:00
|
|
|
daytimes = models.ForeignKey(
|
|
|
|
'daytimes.DayTime', related_name='DayTime_full_name', on_delete=models.CASCADE, null=True)
|
2023-04-22 14:07:08 +08:00
|
|
|
|
2023-04-22 11:00:04 +08:00
|
|
|
date_created = models.DateTimeField(default=now, editable=False)
|
2023-04-22 15:02:38 +08:00
|
|
|
max_slots = models.IntegerField(default=50)
|
2023-04-22 11:00:04 +08:00
|
|
|
|
2023-04-22 14:14:53 +08:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
self.name = f"{self.subject} : {self.professor}"
|
2023-04-22 15:31:58 +08:00
|
|
|
self.year_level = self.subject.year_level
|
2023-04-22 14:14:53 +08:00
|
|
|
super().save(*args, **kwargs)
|
2023-04-22 11:59:16 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
2023-04-22 14:14:53 +08:00
|
|
|
return self.name
|
2023-04-22 11:59:16 +08:00
|
|
|
|
2023-04-22 11:00:04 +08:00
|
|
|
|
|
|
|
class StudentSchedule(models.Model):
|
|
|
|
schedule = models.ForeignKey(
|
|
|
|
'schedules.Schedule', on_delete=models.CASCADE)
|
|
|
|
student_assigned = models.ForeignKey(
|
|
|
|
'students.Student', on_delete=models.CASCADE)
|
|
|
|
date_joined = models.DateTimeField(default=now, editable=False)
|
2023-04-22 13:42:09 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.schedule
|