from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.utils.translation import ugettext_lazy as _

from .models import User


class PyConUserCreationForm(UserCreationForm):
    """
    A form that creates a user, with no privileges, from the given email and
    password.
    """

    class Meta:
        model = User
        fields = ('email', )


class PyConUserChangeForm(UserChangeForm):
    """A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin's
    password hash display field.
    """

    class Meta:
        model = User
        fields = '__all__'


class PyConUserAdmin(UserAdmin):
    # The forms to add and change user instances

    # The fields to be used in displaying the User model.
    # These override the definitions on the base UserAdmin
    # that reference the removed 'username' field
    fieldsets = ((None, {
        'fields': ('email', 'password')
    }), (_('Permissions'), {
        'fields': ('is_active', 'is_staff', 'is_superuser')
    }), (_('Important dates'), {
        'fields': ('last_login', 'date_joined')
    }), )
    add_fieldsets = ((None, {
        'classes': ('wide', ),
        'fields': ('email', 'password1', 'password2')
    }), )
    form = PyConUserChangeForm
    add_form = PyConUserCreationForm
    readonly_fields = ('date_joined', )
    list_display = ('email', 'is_staff', 'is_superuser')
    search_fields = ('email', )
    ordering = ('email', )


admin.site.register(User, PyConUserAdmin)

Add user admin