mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2025-05-16 19:38:45 +08:00
Initial transition to move relationships from subject to schedules
This commit is contained in:
parent
392bf195ae
commit
134df378c3
31 changed files with 334 additions and 22 deletions
|
@ -0,0 +1,29 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 01:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subjects', '0004_remove_subject_enrolled_count_subjectstudent_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='subject',
|
||||
name='code',
|
||||
field=models.CharField(default='PLCHLDER-1', max_length=20),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='subject',
|
||||
name='semester',
|
||||
field=models.CharField(choices=[('1st Semester', 'First Sem'), ('2nd Semester', 'Second Sem')], default='1st Semester', max_length=20),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='subject',
|
||||
name='year_level',
|
||||
field=models.CharField(choices=[('1st Year', 'First Year'), ('2nd Year', 'Second Year'), ('3rd Year', 'Third Year'), ('4th Year', 'Fourth Year')], max_length=20),
|
||||
),
|
||||
]
|
17
infotech/subjects/migrations/0006_remove_subject_students.py
Normal file
17
infotech/subjects/migrations/0006_remove_subject_students.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 02:49
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('subjects', '0005_subject_code_alter_subject_semester_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='subject',
|
||||
name='students',
|
||||
),
|
||||
]
|
17
infotech/subjects/migrations/0007_delete_subjectstudent.py
Normal file
17
infotech/subjects/migrations/0007_delete_subjectstudent.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 4.2 on 2023-04-22 02:58
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('students', '0005_remove_student_enrolled_subjects'),
|
||||
('subjects', '0006_remove_subject_students'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name='SubjectStudent',
|
||||
),
|
||||
]
|
|
@ -12,24 +12,15 @@ class Subject(models.Model):
|
|||
FOURTH_YEAR = '4th Year'
|
||||
|
||||
class Semesters(models.TextChoices):
|
||||
FIRST_SEM = 'Sem-1', '1st Semester'
|
||||
SECOND_SEM = 'Sem-2', '2nd Semester'
|
||||
FIRST_SEM = '1st Semester'
|
||||
SECOND_SEM = '2nd Semester'
|
||||
|
||||
name = models.CharField(max_length=40)
|
||||
code = models.CharField(max_length=20)
|
||||
max_slots = models.IntegerField(default=60)
|
||||
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
||||
semester = models.CharField(
|
||||
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
||||
|
||||
students = models.ManyToManyField(
|
||||
'students.Student', related_name='SubjectStudent_student_assigned', through='subjects.SubjectStudent')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class SubjectStudent(models.Model):
|
||||
subject = models.ForeignKey('subjects.Subject', on_delete=models.CASCADE)
|
||||
student_assigned = models.ForeignKey(
|
||||
'students.Student', on_delete=models.CASCADE, null=True)
|
||||
date_joined = models.DateTimeField(default=now, editable=False)
|
||||
|
|
|
@ -5,11 +5,9 @@ from students.models import Student
|
|||
|
||||
|
||||
class SubjectSerializer(serializers.HyperlinkedModelSerializer):
|
||||
students = serializers.SlugRelatedField(
|
||||
queryset=Student.objects.all(), many=True, slug_field='last_name', allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = Subject
|
||||
fields = ('id', 'name', 'students',
|
||||
fields = ('id', 'name',
|
||||
'max_slots', 'year_level', 'semester')
|
||||
read_only_fields = ('id',)
|
||||
read_only_fields = ['id']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue