12👍
✅
I have to answer my question because now I know the solution:
The way I described in the start post should work. The docs are just wrong:
https://code.djangoproject.com/ticket/29192
8👍
add in models.py
from django.contrib.auth.models import User
User._meta.get_field('email')._unique = True
User._meta.get_field('email').blank = False
User._meta.get_field('email').null = False
- [Django]-Django – Circular model import issue
- [Django]-Create OneToOne instance on model creation
- [Django]-How to upload a file in Django?
1👍
Edit: You have to subclass AbstractBaseUser and implement all other attributes too.
from django.contrib.auth.models import AbstractBaseUser, UserManager
class User(AbstractBaseUser):
email = models.EmailField(_('email address'), blank=False)
objects = UserManager()
Second edit:
Aliquis answer is the correct one. Current documentation is simply wrong: “It is an error to have fields in the abstract base class with the same name as those in the child (and Django will raise an exception).”
👤jazz
- [Django]-Using Django Managers vs. staticmethod on Model class directly
- [Django]-How can I obtain the model's name or the content type of a Django object?
- [Django]-Upgrading from Django 1.6 (with south) to 1.8 doesn't modify 'last_login' on the user table
Source:stackexchange.com