1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00
nk20/apps/member/admin.py

43 lines
1.1 KiB
Python
Raw Normal View History

2020-02-18 20:30:26 +00:00
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
2019-07-08 11:59:31 +00:00
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
2019-08-11 14:22:52 +00:00
from .forms import ProfileForm
2019-07-17 07:49:59 +00:00
from .models import Club, Membership, Profile, Role
2019-07-08 11:59:31 +00:00
class ProfileInline(admin.StackedInline):
2019-07-16 07:05:41 +00:00
"""
Inline user profile in user admin
"""
2019-07-08 11:59:31 +00:00
model = Profile
can_delete = False
class CustomUserAdmin(UserAdmin):
2020-03-07 21:28:59 +00:00
inlines = (ProfileInline,)
2019-07-08 11:59:31 +00:00
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
2020-03-07 21:28:59 +00:00
list_select_related = ('profile',)
2019-08-11 14:22:52 +00:00
form = ProfileForm
2019-07-08 11:59:31 +00:00
def get_inline_instances(self, request, obj=None):
"""
When creating a new user don't show profile one the first step
"""
if not obj:
return list()
return super().get_inline_instances(request, obj)
2019-07-17 07:49:59 +00:00
# Update Django User with profile
2019-07-08 11:59:31 +00:00
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
2019-07-17 07:49:59 +00:00
# Add other models
2019-07-16 13:17:57 +00:00
admin.site.register(Club)
2019-07-17 07:49:59 +00:00
admin.site.register(Membership)
admin.site.register(Role)