StudE-Backend/stude/accounts/admin.py

35 lines
1,013 B
Python
Raw Normal View History

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
from year_levels.models import Year_Level
from semesters.models import Semester
from courses.models import Course
class CustomUserForm(forms.ModelForm):
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)
avatar = forms.ImageField(required=False)
class Meta:
model = CustomUser
fields = '__all__'
2023-06-26 19:10:04 +08:00
class CustomUserAdmin(UserAdmin):
model = CustomUser
form = CustomUserForm
fieldsets = UserAdmin.fieldsets + (
(None, {'fields': ('student_id_number',
2023-06-27 14:38:07 +08:00
'year_level', 'semester', 'course', 'avatar', 'is_student', 'is_banned')}),
)
admin.site.register(CustomUser, CustomUserAdmin)