2023-07-04 19:22:21 +08:00
|
|
|
from django import forms
|
2023-06-26 19:10:04 +08:00
|
|
|
from django.contrib import admin
|
2023-06-26 19:45:58 +08:00
|
|
|
from django.contrib.auth.admin import UserAdmin
|
|
|
|
from .models import CustomUser
|
2023-07-04 19:22:21 +08:00
|
|
|
from year_levels.models import Year_Level
|
|
|
|
from semesters.models import Semester
|
|
|
|
from courses.models import Course
|
2023-09-12 19:55:05 +08:00
|
|
|
from subjects.models import SubjectInstance
|
2023-09-12 20:06:41 +08:00
|
|
|
from django.contrib.admin.widgets import FilteredSelectMultiple
|
2023-07-04 19:22:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
class CustomUserForm(forms.ModelForm):
|
2023-07-27 00:10:53 +08:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(CustomUserForm, self).__init__(*args, **kwargs)
|
|
|
|
if self.instance:
|
2023-09-12 19:55:05 +08:00
|
|
|
self.fields['subjects'].queryset = SubjectInstance.objects.filter(
|
2023-09-12 19:57:39 +08:00
|
|
|
course=self.instance.course)
|
2023-07-27 00:10:53 +08:00
|
|
|
|
2023-07-04 19:22:21 +08:00
|
|
|
year_level = forms.ModelChoiceField(
|
|
|
|
queryset=Year_Level.objects.all(), required=False)
|
|
|
|
semester = forms.ModelChoiceField(
|
|
|
|
queryset=Semester.objects.all(), required=False)
|
|
|
|
course = forms.ModelChoiceField(
|
|
|
|
queryset=Course.objects.all(), required=False)
|
2023-07-18 15:51:06 +08:00
|
|
|
subjects = forms.ModelMultipleChoiceField(
|
2023-09-12 20:06:41 +08:00
|
|
|
queryset=SubjectInstance.objects.none(), required=False, widget=FilteredSelectMultiple("Subjects", is_stacked=False))
|
2023-07-04 19:22:21 +08:00
|
|
|
avatar = forms.ImageField(required=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = CustomUser
|
|
|
|
fields = '__all__'
|
2023-06-26 19:10:04 +08:00
|
|
|
|
2023-06-27 00:06:20 +08:00
|
|
|
|
|
|
|
class CustomUserAdmin(UserAdmin):
|
|
|
|
model = CustomUser
|
2023-07-04 19:22:21 +08:00
|
|
|
form = CustomUserForm
|
2023-06-27 00:06:20 +08:00
|
|
|
|
|
|
|
fieldsets = UserAdmin.fieldsets + (
|
|
|
|
(None, {'fields': ('student_id_number',
|
2023-07-26 23:32:03 +08:00
|
|
|
'year_level', 'semester', 'course', 'subjects', 'avatar', 'is_student', 'irregular')}),
|
2023-06-27 00:06:20 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(CustomUser, CustomUserAdmin)
|