Overhauled the entire subjects app to be more simplified and to remove anomalies when filtering in queries

This commit is contained in:
Keannu Christian Bernasol 2023-07-26 12:14:19 +08:00
parent 4b82ffbbc2
commit 0eff07a1ae
25 changed files with 122 additions and 407 deletions

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-07-18 07:43
# Generated by Django 4.2.3 on 2023-07-26 03:53
import django.contrib.gis.db.models.fields
from django.db import migrations, models

View file

@ -4,7 +4,7 @@ from rest_framework.exceptions import PermissionDenied
from rest_framework.permissions import IsAuthenticated
from .serializers import StudyGroupSerializer
from .models import StudyGroup
from subjects.models import SubjectCourse
from subjects.models import SubjectInstance
# Create your views here.
@ -24,15 +24,16 @@ class StudyGroupListView(generics.ListAPIView):
# Get the user's course
user_course = user.course
print(user_course)
# Get subject ids related to the user's course through SubjectCourse
subject_ids = SubjectCourse.objects.filter(
# Get subject names related to the user's course
subject_names = SubjectInstance.objects.filter(
course=user_course
).values_list('subject', flat=True)
print(subject_ids)
print(subject_names)
# Now fetch the StudyGroups with the subjects from the obtained subject_ids
studygroups = StudyGroup.objects.filter(subject_id__in=subject_ids)
# Now fetch the StudyGroups with the matching subject names
studygroups = StudyGroup.objects.filter(subject_name__in=subject_names)
return studygroups