daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from authtools.models import AbstractEmailUser
  2. from django.db import models
  3.  
  4. from authtools.models import UserManager as BaseUserManager
  5. from mysite.models import UserType
  6. from mysite.models import Organisation
  7.  
  8.  
  9. class UserManager(BaseUserManager):
  10.     def create_superuser(self, **kwargs):
  11.         user = self.create_user(**kwargs)
  12.         user.is_superuser = True
  13.         user.is_staff = True
  14.         user.user_type = UserType.objects.get(name='ADMIN')
  15.         user.save(using=self._db)
  16.         return user
  17.  
  18.     def create_user(self, email, password=None, **kwargs):
  19.         user = super().create_user(email, password, kwargs)
  20.         user.email_user("Register Confirm", "welcome", "admin@mysite.com")
  21.  
  22.  
  23. class User(AbstractEmailUser):
  24.  
  25.     first_name = models.CharField(max_length=255, blank=True)
  26.     last_name = models.CharField(max_length=255, blank=True)
  27.     user_type = models.ForeignKey(UserType, on_delete=models.CASCADE)
  28.  
  29.     organisation = models.ForeignKey(Organisation, null=True, blank=True, on_delete=models.CASCADE)
  30.  
  31.     modified = models.DateTimeField(auto_now=True)
  32.  
  33.     objects = UserManager()
  34.  
  35.     REQUIRED_FIELDS = ['first_name', 'last_name']
  36.  
  37.     class Meta:
  38.         db_table = 'users'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top