class Account(AbstractBaseUser, PermissionsMixin):
email = models.EmailField('Email', max_length=150, unique=True)
name = models.CharField('Имя', max_length=255, blank=True, unique=True)
is_active = models.BooleanField('Активный?', default=False)
is_staff = models.BooleanField('Модератор?', default=False)
is_superuser = models.BooleanField('Админ?', default=False)
date_joined = models.DateTimeField('Дата создания', auto_now_add=True)
USERNAME_FIELD = 'name'
REQUIRED_FIELDS = ['email']
objects = UserManager()
def __str__(self):
return self.name
def get_full_name(self):
return self.name
def get_email(self):
return self.email
def has_perm(self, perm, obj=None):
return True
def has_module_perms(self, app_label):
return True
class Meta:
verbose_name = 'Пользователь'
verbose_name_plural = 'Пользователи'
class AccountAdmin(BaseUserAdmin):
add_form = UserAdminCreationForm
list_display = ['name', 'email', 'is_superuser']
list_filter = ['is_superuser', 'is_active', 'is_staff']
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Информация', {'fields': ('name', )}),
('Разрешения', {'fields': ('is_active',
'is_superuser', 'is_staff', 'groups', 'user_permissions')}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('name', 'email', 'password1', 'password2', 'groups', 'user_permissions')}
),
)
search_fields = ['email']
ordering = ['email']
filter_horizontal = ('groups', 'user_permissions')
admin.site.register(Account, AccountAdmin)