text: from django.utils.translation import ugettext_lazy as _
  from django.contrib import admin
  from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
  from .models import Profile, User
  
  
  class ProfileInline(admin.StackedInline):
      model = Profile
      can_delete = False
      verbose_name_plural = 'Profile'
      fk_name = 'user'
  
  
  @admin.register(User)
  class UserAdmin(DjangoUserAdmin):
      """Define admin model for custom User model with no email field."""
      inlines = (ProfileInline,)
      list_select_related = ('profile',)
      readonly_fields = ('last_login', 'date_joined',)
  
      fieldsets = (
          (None, {'fields': ('email', 'password')}),
          (_('Personal info'), {'fields': ('first_name', 'last_name')}),
          (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',)}), # 'groups', 'user_permissions')}),
          (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
      )
      add_fieldsets = (
          (None, {
              'classes': ('wide',),
              'fields': ('email', 'password1', 'password2', 'first_name', 'last_name'),
          }),
      )
      list_display = ('email', 'first_name', 'last_name', 'is_staff', 'get_role')
      search_fields = ('email', 'first_name', 'last_name')
      ordering = ('email',)
  
      def get_role(self, instance):
          return instance.profile.role
  
      get_role.short_description = 'Role'
  
      def get_inline_instances(self, request, obj=None):
          if not obj:
              return list()
          return super().get_inline_instances(request, obj)
  