1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-27 02:43:01 +00:00
nk20/member/admin.py

39 lines
1.0 KiB
Python
Raw Normal View History

2019-07-08 11:59:31 +00:00
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
# 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
from .forms import CustomUserChangeForm
2019-07-16 13:42:31 +00:00
from .models import Club, Profile
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):
inlines = (ProfileInline,)
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
list_select_related = ('profile',)
form = CustomUserChangeForm
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)
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
2019-07-16 13:17:57 +00:00
admin.site.register(Club)