site_tps/users/admin.py
2018-03-01 11:25:34 +01:00

44 lines
1 KiB
Python

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.admin import GroupAdmin as BaseGroupAdmin
from django.contrib.auth.models import User, Group
from .models import UserProfile, SchoolProfile
# Define an inline admin descriptor for Employee model
# which acts a bit like a singleton
class UserInline(admin.StackedInline):
model = UserProfile
can_delete = False
verbose_name_plural = 'user profiles'
# Define a new User admin
class UserAdmin(BaseUserAdmin):
inlines = (UserInline, )
# Define an inline admin descriptor for Employee model
# which acts a bit like a singleton
class SchoolInline(admin.StackedInline):
model = SchoolProfile
can_delete = False
verbose_name_plural = 'schools'
fk_name = 'admins'
# Define a new User admin
class GroupAdmin(BaseGroupAdmin):
inlines = (SchoolInline, )
# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
admin.site.unregister(Group)
admin.site.register(Group, GroupAdmin)