Issue
Here is what i want to try, I have a User model inherited from Abstract user with custom manager, i need a feeld in CustomUser model to choose either Seller model or Customer model
class CustomUser(AbstractUser):
is_seller = models.BooleanField(default=False)
is_customer = models.BooleanField(default=False)
user_type = ? "I want to have a choice feild to choose either Seller or
Customer model"
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
objects = CustomUserManager()
class CustomUserManager(BaseUserManager):
use_in_migrations = True
def create_user(self, email, password=None, **extra_fields):
if not email:
return ValueError('Email required')
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save()
return user
def create_superuser(self, email, password, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault('is_active', True)
if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff true')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser true')
return self.create_user(email, password, **extra_fields)
class SellerDetails(models.Model):
pass
class CustomerDetails(models.Model):
pass
Solution
Have you looked at Django Content Types Framework? Have a look at it here
This can help you in achieving what you want.
Here is a very simple to understand article on this.
Answered By - Arun T
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.