mirror of
https://github.com/lemeow125/InfoTech-Backend.git
synced 2024-11-17 06:29:26 +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
1
Pipfile
1
Pipfile
|
@ -8,6 +8,7 @@ django = "*"
|
||||||
djangorestframework = "*"
|
djangorestframework = "*"
|
||||||
djoser = "*"
|
djoser = "*"
|
||||||
python-dotenv = "*"
|
python-dotenv = "*"
|
||||||
|
psycopg2 = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
autopep8 = "*"
|
autopep8 = "*"
|
||||||
|
|
89
Pipfile.lock
generated
89
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "7c48093ecdc0024d188ac68adf4d0b32d9de65071152b8039b55c664c13d606c"
|
"sha256": "69c88b6f5857d719e9f73d2962d7e7a7db416eb7363a0fe6426fe967ad931be7"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
@ -198,32 +198,28 @@
|
||||||
},
|
},
|
||||||
"cryptography": {
|
"cryptography": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:103e8f7155f3ce2ffa0049fe60169878d47a4364b277906386f8de21c9234aa1",
|
"sha256:0a4e3406cfed6b1f6d6e87ed243363652b2586b2d917b0609ca4f97072994405",
|
||||||
"sha256:23df8ca3f24699167daf3e23e51f7ba7334d504af63a94af468f468b975b7dd7",
|
"sha256:1e0af458515d5e4028aad75f3bb3fe7a31e46ad920648cd59b64d3da842e4356",
|
||||||
"sha256:2725672bb53bb92dc7b4150d233cd4b8c59615cd8288d495eaa86db00d4e5c06",
|
"sha256:2803f2f8b1e95f614419926c7e6f55d828afc614ca5ed61543877ae668cc3472",
|
||||||
"sha256:30b1d1bfd00f6fc80d11300a29f1d8ab2b8d9febb6ed4a38a76880ec564fae84",
|
"sha256:28d63d75bf7ae4045b10de5413fb1d6338616e79015999ad9cf6fc538f772d41",
|
||||||
"sha256:35d658536b0a4117c885728d1a7032bdc9a5974722ae298d6c533755a6ee3915",
|
"sha256:32057d3d0ab7d4453778367ca43e99ddb711770477c4f072a51b3ca69602780a",
|
||||||
"sha256:50cadb9b2f961757e712a9737ef33d89b8190c3ea34d0fb6675e00edbe35d074",
|
"sha256:3a4805a4ca729d65570a1b7cac84eac1e431085d40387b7d3bbaa47e39890b88",
|
||||||
"sha256:5f8c682e736513db7d04349b4f6693690170f95aac449c56f97415c6980edef5",
|
"sha256:63dac2d25c47f12a7b8aa60e528bfb3c51c5a6c5a9f7c86987909c6c79765554",
|
||||||
"sha256:6236a9610c912b129610eb1a274bdc1350b5df834d124fa84729ebeaf7da42c3",
|
"sha256:650883cc064297ef3676b1db1b7b1df6081794c4ada96fa457253c4cc40f97db",
|
||||||
"sha256:788b3921d763ee35dfdb04248d0e3de11e3ca8eb22e2e48fef880c42e1f3c8f9",
|
"sha256:6f2bbd72f717ce33100e6467572abaedc61f1acb87b8d546001328d7f466b778",
|
||||||
"sha256:8bc0008ef798231fac03fe7d26e82d601d15bd16f3afaad1c6113771566570f3",
|
"sha256:7c872413353c70e0263a9368c4993710070e70ab3e5318d85510cc91cce77e7c",
|
||||||
"sha256:8f35c17bd4faed2bc7797d2a66cbb4f986242ce2e30340ab832e5d99ae60e011",
|
"sha256:918cb89086c7d98b1b86b9fdb70c712e5a9325ba6f7d7cfb509e784e0cfc6917",
|
||||||
"sha256:b49a88ff802e1993b7f749b1eeb31134f03c8d5c956e3c125c75558955cda536",
|
"sha256:9618a87212cb5200500e304e43691111570e1f10ec3f35569fdfcd17e28fd797",
|
||||||
"sha256:bc0521cce2c1d541634b19f3ac661d7a64f9555135e9d8af3980965be717fd4a",
|
"sha256:a805a7bce4a77d51696410005b3e85ae2839bad9aa38894afc0aa99d8e0c3160",
|
||||||
"sha256:bc5b871e977c8ee5a1bbc42fa8d19bcc08baf0c51cbf1586b0e87a2694dde42f",
|
"sha256:cc3a621076d824d75ab1e1e530e66e7e8564e357dd723f2533225d40fe35c60c",
|
||||||
"sha256:c43ac224aabcbf83a947eeb8b17eaf1547bce3767ee2d70093b461f31729a480",
|
"sha256:cd033d74067d8928ef00a6b1327c8ea0452523967ca4463666eeba65ca350d4c",
|
||||||
"sha256:d15809e0dbdad486f4ad0979753518f47980020b7a34e9fc56e8be4f60702fac",
|
"sha256:cf91e428c51ef692b82ce786583e214f58392399cf65c341bc7301d096fa3ba2",
|
||||||
"sha256:d7d84a512a59f4412ca8549b01f94be4161c94efc598bf09d027d67826beddc0",
|
"sha256:d36bbeb99704aabefdca5aee4eba04455d7a27ceabd16f3b3ba9bdcc31da86c4",
|
||||||
"sha256:e029b844c21116564b8b61216befabca4b500e6816fa9f0ba49527653cae2108",
|
"sha256:d8aa3609d337ad85e4eb9bb0f8bcf6e4409bfb86e706efa9a027912169e89122",
|
||||||
"sha256:e8a0772016feeb106efd28d4a328e77dc2edae84dfbac06061319fdb669ff828",
|
"sha256:f5d7b79fa56bc29580faafc2ff736ce05ba31feaa9d4735048b0de7d9ceb2b94"
|
||||||
"sha256:e944fe07b6f229f4c1a06a7ef906a19652bdd9fd54c761b0ff87e83ae7a30354",
|
|
||||||
"sha256:eb40fe69cfc6f5cdab9a5ebd022131ba21453cf7b8a7fd3631f45bbf52bed612",
|
|
||||||
"sha256:fa507318e427169ade4e9eccef39e9011cdc19534f55ca2f36ec3f388c1f70f3",
|
|
||||||
"sha256:ffd394c7896ed7821a6d13b24657c6a34b6e2650bd84ae063cf11ccffa4f1a97"
|
|
||||||
],
|
],
|
||||||
"markers": "python_version >= '3.6'",
|
"markers": "python_version >= '3.6'",
|
||||||
"version": "==39.0.2"
|
"version": "==40.0.1"
|
||||||
},
|
},
|
||||||
"defusedxml": {
|
"defusedxml": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
@ -235,11 +231,11 @@
|
||||||
},
|
},
|
||||||
"django": {
|
"django": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:44f714b81c5f190d9d2ddad01a532fe502fa01c4cb8faf1d081f4264ed15dcd8",
|
"sha256:ad33ed68db9398f5dfb33282704925bce044bef4261cd4fb59e4e7f9ae505a78",
|
||||||
"sha256:f2f431e75adc40039ace496ad3b9f17227022e8b11566f4b363da44c7e44761e"
|
"sha256:c36e2ab12824e2ac36afa8b2515a70c53c7742f0d6eaefa7311ec379558db997"
|
||||||
],
|
],
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==4.1.7"
|
"version": "==4.2"
|
||||||
},
|
},
|
||||||
"django-templated-mail": {
|
"django-templated-mail": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
@ -359,6 +355,25 @@
|
||||||
"markers": "python_version >= '3.6'",
|
"markers": "python_version >= '3.6'",
|
||||||
"version": "==3.2.2"
|
"version": "==3.2.2"
|
||||||
},
|
},
|
||||||
|
"psycopg2": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:11aca705ec888e4f4cea97289a0bf0f22a067a32614f6ef64fcf7b8bfbc53744",
|
||||||
|
"sha256:1861a53a6a0fd248e42ea37c957d36950da00266378746588eab4f4b5649e95f",
|
||||||
|
"sha256:2362ee4d07ac85ff0ad93e22c693d0f37ff63e28f0615a16b6635a645f4b9214",
|
||||||
|
"sha256:36c941a767341d11549c0fbdbb2bf5be2eda4caf87f65dfcd7d146828bd27f39",
|
||||||
|
"sha256:53f4ad0a3988f983e9b49a5d9765d663bbe84f508ed655affdb810af9d0972ad",
|
||||||
|
"sha256:869776630c04f335d4124f120b7fb377fe44b0a7645ab3c34b4ba42516951889",
|
||||||
|
"sha256:a8ad4a47f42aa6aec8d061fdae21eaed8d864d4bb0f0cade5ad32ca16fcd6258",
|
||||||
|
"sha256:b81fcb9ecfc584f661b71c889edeae70bae30d3ef74fa0ca388ecda50b1222b7",
|
||||||
|
"sha256:d24ead3716a7d093b90b27b3d73459fe8cd90fd7065cf43b3c40966221d8c394",
|
||||||
|
"sha256:ded2faa2e6dfb430af7713d87ab4abbfc764d8d7fb73eafe96a24155f906ebf5",
|
||||||
|
"sha256:f15158418fd826831b28585e2ab48ed8df2d0d98f502a2b4fe619e7d5ca29011",
|
||||||
|
"sha256:f75001a1cbbe523e00b0ef896a5a1ada2da93ccd752b7636db5a99bc57c44494",
|
||||||
|
"sha256:f7a7a5ee78ba7dc74265ba69e010ae89dae635eea0e97b055fb641a01a31d2b1"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==2.9.6"
|
||||||
|
},
|
||||||
"pycparser": {
|
"pycparser": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9",
|
"sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9",
|
||||||
|
@ -391,10 +406,10 @@
|
||||||
},
|
},
|
||||||
"pytz": {
|
"pytz": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:01a0681c4b9684a28304615eba55d1ab31ae00bf68ec157ec3708a8182dbbcd0",
|
"sha256:1d8ce29db189191fb55338ee6d0387d82ab59f3d00eac103412d64e0ebd0c588",
|
||||||
"sha256:78f4f37d8198e0627c5f1143240bb0206b8691d8d7ac6d78fee88b78733f8c4a"
|
"sha256:a151b3abb88eda1d4e34a9814df37de2a80e301e68ba0fd856fb9b46bfbbbffb"
|
||||||
],
|
],
|
||||||
"version": "==2022.7.1"
|
"version": "==2023.3"
|
||||||
},
|
},
|
||||||
"requests": {
|
"requests": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
@ -430,11 +445,11 @@
|
||||||
},
|
},
|
||||||
"social-auth-core": {
|
"social-auth-core": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:359f6be5bb2d4caef6500eb6e1b40821a40dde9add8d339d539b1adbba2c9bf7",
|
"sha256:29f5ea3174162797ccb9b849f7a38a9490bfb920304ecd9b7f63c6c3a5ceb7a3",
|
||||||
"sha256:89536f218fa1a769caeaa56ef90f965ea50a81b9a7e3e5a2c5a61b832df11bde"
|
"sha256:cff78e0707ed0f6bdd3beec6ce713591875492b98272ea6298cc173912e3234b"
|
||||||
],
|
],
|
||||||
"markers": "python_version >= '3.6'",
|
"markers": "python_version >= '3.6'",
|
||||||
"version": "==4.4.0"
|
"version": "==4.4.1"
|
||||||
},
|
},
|
||||||
"sqlparse": {
|
"sqlparse": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
@ -446,11 +461,11 @@
|
||||||
},
|
},
|
||||||
"tzdata": {
|
"tzdata": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:2b88858b0e3120792a3c0635c23daf36a7d7eeeca657c323da299d2094402a0d",
|
"sha256:11ef1e08e54acb0d4f95bdb1be05da659673de4acbd21bf9c69e94cc5e907a3a",
|
||||||
"sha256:fe5f866eddd8b96e9fcba978f8e503c909b19ea7efda11e52e39494bad3a7bfa"
|
"sha256:7e65763eef3120314099b6939b5546db7adce1e7d6f2e179e3df563c70511eda"
|
||||||
],
|
],
|
||||||
"markers": "sys_platform == 'win32'",
|
"markers": "sys_platform == 'win32'",
|
||||||
"version": "==2022.7"
|
"version": "==2023.3"
|
||||||
},
|
},
|
||||||
"uritemplate": {
|
"uritemplate": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
|
|
@ -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.db import models
|
||||||
from django.contrib.postgres.fields import ArrayField
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,10 +36,15 @@ class Student(models.Model):
|
||||||
clearance_done = models.BooleanField()
|
clearance_done = models.BooleanField()
|
||||||
pta_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)
|
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
||||||
current_semester = models.CharField(
|
current_semester = models.CharField(
|
||||||
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
||||||
|
|
||||||
def __str__(self):
|
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 rest_framework import serializers
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from .models import Student
|
from .models import Student
|
||||||
|
from subjects.models import Subject
|
||||||
|
|
||||||
|
|
||||||
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
enrolled_subjects = serializers.SlugRelatedField(
|
||||||
|
queryset=Subject.objects.all(), many=True, slug_field='name', allow_null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Student
|
model = Student
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
# Generated by Django 4.2 on 2023-04-11 15:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('students', '0003_remove_student_enrolled_subjects'),
|
||||||
|
('subjects', '0003_subject_semester'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='subject',
|
||||||
|
name='enrolled_count',
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SubjectStudent',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('date_joined', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
|
||||||
|
('student_assigned', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='students.student')),
|
||||||
|
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subjects.subject')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='subject',
|
||||||
|
name='students',
|
||||||
|
field=models.ManyToManyField(related_name='SubjectStudent_student_assigned', through='subjects.SubjectStudent', to='students.student'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,5 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
|
from django.utils.timezone import now
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,16 +16,20 @@ class Subject(models.Model):
|
||||||
SECOND_SEM = 'Sem-2', '2nd Semester'
|
SECOND_SEM = 'Sem-2', '2nd Semester'
|
||||||
|
|
||||||
name = models.CharField(max_length=40)
|
name = models.CharField(max_length=40)
|
||||||
enrolled_count = models.IntegerField(
|
|
||||||
default=0,
|
|
||||||
validators=[
|
|
||||||
MaxValueValidator(60),
|
|
||||||
MinValueValidator(0)
|
|
||||||
])
|
|
||||||
max_slots = models.IntegerField(default=60)
|
max_slots = models.IntegerField(default=60)
|
||||||
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
year_level = models.CharField(max_length=20, choices=YearLevels.choices)
|
||||||
semester = models.CharField(
|
semester = models.CharField(
|
||||||
max_length=20, choices=Semesters.choices, default=Semesters.FIRST_SEM)
|
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):
|
def __str__(self):
|
||||||
return self.name
|
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)
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from .models import Subject
|
from .models import Subject
|
||||||
|
from students.models import Student
|
||||||
|
|
||||||
|
|
||||||
class SubjectSerializer(serializers.HyperlinkedModelSerializer):
|
class SubjectSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
enrolled_count = serializers.IntegerField(required=False, default=0)
|
students = serializers.SlugRelatedField(
|
||||||
|
queryset=Student.objects.all(), many=True, slug_field='full_name', allow_null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Subject
|
model = Subject
|
||||||
fields = ('id', 'name', 'enrolled_count',
|
fields = ('id', 'name', 'students',
|
||||||
'max_slots', 'year_level', 'semester')
|
'max_slots', 'year_level', 'semester')
|
||||||
read_only_fields = ('id',)
|
read_only_fields = ('id',)
|
||||||
|
|
Loading…
Reference in a new issue