Guest User

Untitled

a guest
Nov 28th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. class User(AbstractBaseUser, PermissionsMixin):
  2.  
  3. mobile = models.CharField(max_length=15,unique=True)
  4. email = models.EmailField(unique=True)
  5. first_name = models.CharField(max_length=30)
  6. last_name = models.CharField(max_length=30,blank=True)
  7. date_joined = models.DateTimeField(auto_now_add=True)
  8. is_on_booking = models.BooleanField(default=False)
  9. is_acitve = models.BooleanField(default=True)
  10. is_staff = models.BooleanField(default=False)
  11. is_superuser = models.BooleanField(default=False)
  12. bookings_count = models.IntegerField(default=0)
  13. GENDER_TYPES = (('male','m'),('female','f'),('other','o'))
  14.  
  15. gender = models.CharField(max_length=15,choices=GENDER_TYPES,blank=True)
  16.  
  17. objects = MyUserManager()
  18.  
  19. USERNAME_FIELD = 'mobile'
  20. REQUIRED_FIELDS = ['email','first_name']
  21.  
  22. class MyUserManager(BaseUserManager):
  23.  
  24. def _create_user(self, mobile, email, first_name, is_staff, is_superuser, password, **extra_fields):
  25. if not mobile:
  26. raise ValueError('User must give a mobile Number')
  27. email = self.normalize_email(email)
  28. user = self.model(mobile=mobile,email=email,first_name=first_name, is_staff=is_staff, is_superuser=is_superuser, **extra_fields)
  29. user.set_password(password)
  30. user.save(using=self._db)
  31. return user
  32.  
  33. def create_user(self, mobile, password=None, email=None, first_name=None, **extra_fields):
  34. return self._create_user(mobile, email, first_name, False, False, password, **extra_fields)
  35.  
  36. def create_superuser(self, mobile, email, first_name, password, **extra_fields):
  37. return self._create_user(mobile, email, first_name, True, True, password, **extra_fields)
  38.  
  39. {
  40. "non_field_errors": [
  41. "Unable to log in with provided credentials."
  42. ]
  43. }
Add Comment
Please, Sign In to add comment