Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib.auth.models import AbstractUser, BaseUserManager
- from django.db import models
- from django.utils.translation import ugettext_lazy as _
- from django.utils import timezone
- class CustomUser(AbstractUser):
- username = None
- email = models.EmailField(_('email address'), unique=True, blank=False)
- is_manager = models.BooleanField(default=False, blank=False)
- USERNAME_FIELD = 'email'
- REQUIRED_FIELDS = []
- def __str__(self):
- return self.email
- class CustomUserManager(BaseUserManager):
- def _create_user(self, email, password, is_staff, is_superuser,is_manager ,**extra_fields):
- now = timezone.now()
- if not email:
- raise ValueError(_(u'The given username must be set'))
- email = self.normalize_email(email)
- user = self.model(email=email,
- is_staff=is_staff, is_active=True,
- is_superuser=is_superuser,is_manager=is_manager , last_login=now,
- date_joined=now, **extra_fields)
- user.set_password(password)
- user.save(using=self._db)
- return user
- def create_user(self, email, password=None, **extra_fields):
- return self._create_user(email, password, False, False, False,
- **extra_fields)
- def create_superuser(self, email, password, **extra_fields):
- return self._create_user(email, password, True, True, True,
- **extra_fields)
Add Comment
Please, Sign In to add comment