4
If you want it to be more flexible inherit from AbstractBaseUser
instead, you will be able to specify your own username field that way, e.g.
class User(AbstractBaseUser):
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
date_joined = models.DateTimeField(
verbose_name=_('date created'),
auto_created=True,
default=timezone.now
)
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
https://docs.djangoproject.com/en/1.7/topics/auth/customizing/#specifying-a-custom-user-model
8
Dont try to override username
field. Just
class CustomUser(AbstractUser, BaseModel):
#here goes other fields
CustomUser._meta.get_field('username').max_length = 70
But I highly recommend to inherit from AbstractBaseUser
instead.
0
As I understood you canβt override any Django ORM modelβs attribute, nor from AbstractUser
, nor from PermissionsMixin
classes. So, If you have your own approach to Permissions, Groups(Roles), even if you want another attribute name than user_permissions
or groups
, then you should inherit from AbstractBaseUser
, doing a lot of copy-paste from AbstractUser
and inherit your Permission
and Group
models from django.db.models.Model
class as @levi and @Hedde van der Heide suggested.
- [Django]-Django Template: Comparing Dictionary Length in IF Statement
- [Django]-Open() "/root/project/static/*.css" failed (13: Permission denied) nginx
- [Django]-Populate CheckboxSelectMultiple with existing data from django model form