daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. TypeError: create_superuser() missing 3 required positional arguments: 'first_name', 'last_name', and 'location'
  2.      
  3. from django.db import models
  4. from django.contrib.auth.models import (
  5.         AbstractBaseUser, BaseUserManager,PermissionsMixin
  6.     )
  7. class UserManager(BaseUserManager):
  8.     # All required field must be passed below as argument
  9.     def create_user(self, mobile_no, role, email, first_name, last_name, location, password=None, is_active=True,is_staff=False, is_admin= False):
  10.         if not mobile_no:
  11.             raise ValueError("User must have an Mobile number as username ")
  12.         if not password:
  13.             raise ValueError("Users must have a password")
  14.  
  15.         user_obj= self.model(
  16.             mobile_no= mobile_no
  17.         )
  18.         user_obj.email = email
  19.         user_obj.set_password(password)
  20.         user_obj.role = role
  21.         user_obj.first_name = first_name
  22.         user_obj.las_name = last_name
  23.         user_obj.is_active = is_active
  24.         user_obj.location = location
  25.         user_obj.is_staff = is_staff
  26.         user_obj.save(using=self._db)
  27.         return user_obj
  28.  
  29.     def create_superuser(self, mobile_no, role, email, first_name, last_name, location, password=None, is_active=True,is_staff=False, is_admin= False):
  30.         user_obj= self.model(
  31.             mobile_no=mobile_no
  32.         )
  33.         user_obj.email = email
  34.         user_obj.set_password(password)
  35.         user_obj.role = role
  36.         user_obj.first_name = first_name
  37.         user_obj.las_name = last_name
  38.         user_obj.location = location
  39.         user_obj.is_staff = True
  40.         user_obj.is_admin = True
  41.         user_obj.is_active = is_active
  42.         user_obj.save(using=self._db)
  43.         return user_obj
  44.  
  45.     def create_staffuser(self, mobile_no, role, email, first_name, last_name, location, password=None, is_active=True,is_staff=False, is_admin= False):
  46.         user_obj= self.model(
  47.             mobile_no=mobile_no
  48.         )
  49.         user_obj.email = email
  50.         user_obj.set_password(password)
  51.         user_obj.role = role
  52.         user_obj.first_name = first_name
  53.         user_obj.las_name = last_name
  54.         user_obj.location = location
  55.         user_obj.is_staff = True
  56.         user_obj.is_admin = False
  57.         user_obj.is_active = is_active
  58.         user_obj.save(using=self._db)
  59.         return user_obj
  60.  
  61.  
  62.     # def get_by_natural_key(self, mobile_no_):
  63.     #     print(mobile_no_)
  64.     #     return self.get(mobile_no=mobile_no_)
  65.  
  66. class User(AbstractBaseUser, PermissionsMixin):
  67.     mobile_no   = models.CharField(max_length=10,unique=True)
  68.     email       = models.EmailField(max_length=255)
  69.     role        = models.CharField(max_length=255)
  70.     first_name  = models.CharField(max_length=30, blank=True)
  71.     last_name   = models.CharField(max_length=30, blank=True)
  72.     location    = models.CharField(max_length=30, blank=True)
  73.     date_joined = models.DateTimeField(auto_now_add=True)
  74.     is_active   = models.BooleanField(default=True)
  75.     is_staff    = models.BooleanField(default=False)
  76.     is_admin    = models.BooleanField(default=False)
  77.  
  78.     USERNAME_FIELD = 'mobile_no'
  79.     REQUIRED_FIELDS = ['email', 'role']
  80.  
  81.     objects= UserManager()
  82.  
  83.     def get_full_name(self):
  84.         return self.first_name + self.last_name
  85.  
  86.     def get_short_name(self):
  87.         return self.mobile_no
  88.  
  89.     def __str__(self):
  90.         return self.mobile_no
  91.  
  92.     @property
  93.     def is_staff(self):
  94.         return self.staff
  95.  
  96.     @property
  97.     def is_admin(self):
  98.         return self.admin
  99.  
  100.     @property
  101.     def is_active(self):
  102.         return self.active
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