I am beginning a new project with Django Rest Framework, and I have a specifical need on the creation of a user: to create an account, you need to give information such as your birthdate, the birthdate of a friend, and several other info.
But it would NOT be relevant for a superuser to give such information, that's why I am looking for a way to require different info for user and for superuser. Do you know if it's possible ?
In the file models.py, I created 2 different classes :
- class UserProfile(AbstractBaseUser, PermissionsMixin)
- class SuperUserProfile(AbstractBaseUser, PermissionsMixin)
These two classes require different info to create an account.
In addition, I created a class to manage user profiles :
class UserProfileManager(BaseUserManager): """Manager for user profiles"""
def create_user(self, name1, firstName1, email1, name2, firstName2, birthDate2, password=None):
"""Create a new user profile"""
email1 = self.normalize_email(emailParrain)
user = self.model(emailParrain=emailParrain,
name1=name1,
firstName1=firstName1,
name2=name2,
firstNameUser=firstNameUser,
birthDateUser=birthDateUser)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, name, password):
"""Create and save a new superuser with given details"""
user = self.create_user(email,password)
user.is_superuser = True
user.is_staff = True
user.save(using=self._db)
return user
But when I do this, I cannot create a superuser with only the info sub-mentionned (email, name, password).