mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2025-05-16 11:28:14 +08:00
Added relationship between subjects and student
This commit is contained in:
parent
ac0f4b5e28
commit
5182dfa8da
9 changed files with 148 additions and 48 deletions
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 4.2 on 2023-04-11 15:10
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('students', '0002_student_current_semester'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='student',
|
||||
name='enrolled_subjects',
|
||||
),
|
||||
]
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 4.2 on 2023-04-11 15:10
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('students', '0003_remove_student_enrolled_subjects'),
|
||||
('subjects', '0004_remove_subject_enrolled_count_subjectstudent_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='student',
|
||||
name='enrolled_subjects',
|
||||
field=models.ManyToManyField(through='subjects.SubjectStudent', to='subjects.subject'),
|
||||
),
|
||||
]
|
|
@ -1,5 +1,4 @@
|
|||
from django.db import models
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
# Create your models here.
|
||||
|
||||
|
||||
|
@ -37,10 +36,15 @@ class Student(models.Model):
|
|||
clearance_done = models.BooleanField()
|
||||
pta_done = models.BooleanField()
|
||||
#
|
||||
enrolled_subjects = models.CharField(max_length=800)
|
||||
enrolled_subjects = models.ManyToManyField(
|
||||
'subjects.Subject', through='subjects.SubjectStudent')
|
||||
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
||||
current_semester = models.CharField(
|
||||
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
return self.first_name
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
return self.first_name + " " + self.middle_name + " " + self.last_name
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
from rest_framework import serializers
|
||||
from django.contrib.auth.models import User
|
||||
from .models import Student
|
||||
from subjects.models import Subject
|
||||
|
||||
|
||||
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||
enrolled_subjects = serializers.SlugRelatedField(
|
||||
queryset=Subject.objects.all(), many=True, slug_field='name', allow_null=True)
|
||||
|
||||
class Meta:
|
||||
model = Student
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue