Advertisement
_jakuta

CustomUserModel

Nov 9th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. from django.db import models
  2. from django.contrib.auth.models import ( AbstractUser, BaseUserManager )
  3.  
  4. class CustomUserModelManager(BaseUserManager):
  5.     pass
  6.  
  7. class CustomUser(AbstractUser):
  8.  
  9.     username = models.CharField(max_length=150, unique=True)
  10.     password = models.CharField(default='', max_length=150)
  11.     email = models.EmailField(max_length=254)
  12.     first_name = models.CharField(max_length=150)
  13.     last_name = models.CharField(max_length=150)
  14.     is_active = models.BooleanField(default=True)
  15.     is_staff = models.BooleanField(default=False)
  16.     is_admin = models.BooleanField(default=False)
  17.     timestamp = models.DateTimeField(auto_now_add=True)
  18.  
  19.     USERNAME_FIELD = 'username'
  20.     REQUIRED_FIELDS = ['password', 'email']
  21.  
  22.     def __unicode__(self):
  23.         return self.username
  24.  
  25.     def __str__(self):
  26.         return self.username
  27.  
  28.     @property
  29.     def is_active(self):
  30.         return self.is_active
  31.  
  32.     @property
  33.     def is_staff(self):
  34.         return self.is_staff
  35.  
  36.     @property
  37.     def is_admin(self):
  38.         return self.is_admin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement