From aeecd1a77c28d763f6f15469460c62df74c6f557 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Tue, 12 Sep 2023 19:55:05 +0800 Subject: [PATCH] Fixed admin page for customuser --- stude/accounts/admin.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stude/accounts/admin.py b/stude/accounts/admin.py index b920935..f2c6065 100644 --- a/stude/accounts/admin.py +++ b/stude/accounts/admin.py @@ -5,15 +5,17 @@ from .models import CustomUser from year_levels.models import Year_Level from semesters.models import Semester from courses.models import Course -from subjects.models import Subject +from subjects.models import SubjectInstance class CustomUserForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(CustomUserForm, self).__init__(*args, **kwargs) if self.instance: - self.fields['subjects'].queryset = Subject.objects.filter( - course=self.instance.course) + self.fields['subjects'].queryset = SubjectInstance.objects.filter( + course=self.instance.course).filter( + year_level=self.instance.year_level).filter( + semester=self.instance.semester) year_level = forms.ModelChoiceField( queryset=Year_Level.objects.all(), required=False) @@ -22,7 +24,7 @@ class CustomUserForm(forms.ModelForm): course = forms.ModelChoiceField( queryset=Course.objects.all(), required=False) subjects = forms.ModelMultipleChoiceField( - queryset=Subject.objects.none(), required=False, widget=forms.CheckboxSelectMultiple) + queryset=SubjectInstance.objects.none(), required=False, widget=forms.CheckboxSelectMultiple) avatar = forms.ImageField(required=False) class Meta: