admin.py 855 Bytes
Newer Older
1 2
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
3 4 5
from django.contrib.auth.forms import UserChangeForm
from rest_framework.authtoken.admin import TokenAdmin

6 7
from .models import User

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

# Handling of the registration of the custom User model to make sure
# we can see all the fields.
# taken from: https://stackoverflow.com/a/15013810


class CustomUserChangeForm(UserChangeForm):
    class Meta(UserChangeForm.Meta):
        model = User


class CustomUserAdmin(UserAdmin):
    form = CustomUserChangeForm

    fieldsets = UserAdmin.fieldsets + (
        (
            None,
            {"fields": ("allow_sharing_personal_info", "secondary_email", "pseudo")},
        ),
    )


admin.site.register(User, CustomUserAdmin)
Florent Chehab's avatar
Florent Chehab committed
31 32

# Pour la génération de token dans l'administration du site.
33
TokenAdmin.raw_id_fields = ("user",)