mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2024-11-16 22:19:25 +08:00
Finalized schedule and student model by adding relationship between both
This commit is contained in:
parent
716b7cf348
commit
0169d69914
4 changed files with 30 additions and 19 deletions
20
infotech/schedules/migrations/0004_schedule_daytimes.py
Normal file
20
infotech/schedules/migrations/0004_schedule_daytimes.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 06:16
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('daytimes', '0001_initial'),
|
||||
('schedules', '0003_schedule_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='schedule',
|
||||
name='daytimes',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='DayTime_full_name', to='daytimes.daytime'),
|
||||
),
|
||||
]
|
|
@ -11,8 +11,8 @@ class Schedule(models.Model):
|
|||
'students.Student', related_name='StudentSchedule_student_assigned', through='schedules.StudentSchedule')
|
||||
professor = models.OneToOneField(
|
||||
'professors.Professor', related_name='Professor_full_name', on_delete=models.CASCADE)
|
||||
# daytimes = models.ForeignKey(
|
||||
# 'daytimes.DayTime', related_name='DayTime_full_name', on_delete=models.CASCADE)
|
||||
daytimes = models.ForeignKey(
|
||||
'daytimes.DayTime', related_name='DayTime_full_name', on_delete=models.CASCADE, null=True)
|
||||
|
||||
date_created = models.DateTimeField(default=now, editable=False)
|
||||
|
||||
|
@ -33,16 +33,3 @@ class StudentSchedule(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return self.schedule
|
||||
|
||||
|
||||
'''
|
||||
class DayTimeSchedule(models.Model):
|
||||
schedule = models.ForeignKey(
|
||||
'schedules.Schedule', on_delete=models.CASCADE)
|
||||
timeschedule = models.ForeignKey(
|
||||
'daytimes.DayTime', on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.schedule
|
||||
|
||||
'''
|
||||
|
|
|
@ -2,6 +2,7 @@ from rest_framework import serializers
|
|||
from .models import Schedule
|
||||
from professors.models import Professor
|
||||
from subjects.models import Subject
|
||||
from daytimes.models import DayTime
|
||||
from students.models import Student
|
||||
|
||||
|
||||
|
@ -9,8 +10,8 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
|||
date_created = serializers.DateTimeField(
|
||||
format="%d-%m-%Y %I:%M%p", read_only=True)
|
||||
|
||||
# students_assigned = serializers.SlugRelatedField(
|
||||
# queryset=Student.objects.all(), slug_field='student_assigned', allow_null=True)
|
||||
students_assigned = serializers.SlugRelatedField(
|
||||
queryset=Student.objects.all(), many=True, slug_field='full_name', allow_null=True)
|
||||
|
||||
professor = serializers.SlugRelatedField(
|
||||
queryset=Professor.objects.all(), slug_field='full_name', allow_null=True)
|
||||
|
@ -18,8 +19,11 @@ class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
|
|||
subject = serializers.SlugRelatedField(
|
||||
queryset=Subject.objects.all(), slug_field='code', allow_null=True)
|
||||
|
||||
daytimes = serializers.SlugRelatedField(
|
||||
queryset=DayTime.objects.all(), slug_field='name', allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = Schedule
|
||||
fields = ('id', 'name', 'subject', 'students_assigned',
|
||||
fields = ('id', 'name', 'subject', 'daytimes', 'students_assigned',
|
||||
'professor', 'date_created')
|
||||
read_only_fields = ('id', 'date_created', 'name')
|
||||
|
|
|
@ -8,7 +8,7 @@ from subjects.models import Subject
|
|||
|
||||
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||
schedules = serializers.SlugRelatedField(
|
||||
queryset=Subject.objects.all(), slug_field='name', allow_null=True)
|
||||
queryset=Subject.objects.all(), many=True, slug_field='name', allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = Student
|
||||
|
|
Loading…
Reference in a new issue