from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import CustomUser

@admin.register(CustomUser)
class CustomUserAdmin(UserAdmin):
    # Configuration de l'affichage en liste
    list_display = ('email', 'is_voter', 'is_staff', 'is_superuser')
    list_filter = ('is_voter', 'is_staff', 'is_superuser')
    ordering = ('email',)
    
    # On adapte les champs affichés car le 'username' n'existe plus
    fieldsets = (
        (None, {'fields': ('email', 'password')}),
        ('Permissions', {'fields': ('is_active', 'is_voter', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}),
        ('Dates importantes', {'fields': ('last_login', 'date_joined')}),
    )
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('email', 'password', 'is_voter', 'is_staff', 'is_active'),
        }),
    )
    search_fields = ('email',)