From 532460e1bad269e8984c9f46e5a2eb4f302a36a4 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 17 Sep 2023 19:40:27 +0800 Subject: [PATCH] Quick fix for subject selection in student status admin --- stude/student_status/admin.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/stude/student_status/admin.py b/stude/student_status/admin.py index 904cec9..2b762d6 100644 --- a/stude/student_status/admin.py +++ b/stude/student_status/admin.py @@ -2,7 +2,7 @@ from django.contrib import admin from .models import StudentStatus from leaflet.admin import LeafletGeoAdmin from django import forms -from subjects.models import SubjectInstance +from subjects.models import SubjectInstance, Subject from accounts.models import CustomUser @@ -14,12 +14,18 @@ class CustomStudentStatusForm(forms.ModelForm): user=self.instance.user).first() user = CustomUser.objects.filter( id=studentstatus.user.id).first() - subjects = SubjectInstance.objects.filter( + subject_instances = SubjectInstance.objects.filter( course=user.course) + # Get the names of the SubjectInstance objects + subject_instance_names = subject_instances.values_list( + 'subject', flat=True) + + # Filter the Subject objects by these names + subjects = Subject.objects.filter(name__in=subject_instance_names) self.fields['subject'].queryset = subjects - subject = forms.ModelMultipleChoiceField( - queryset=SubjectInstance.objects.none(), required=False) + subject = forms.ModelChoiceField( + queryset=Subject.objects.none(), required=False) class Meta: model = StudentStatus