I am working on a web e-commerce project where there will be two types of user (seller, customer). I have been wondering how to implement the logic like fiverr seller and buyer. I have created a user account with two flags yet (is_seller, is_customer).
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=254, unique=True)
name = models.CharField(max_length=254, blank=True)
customer = models.ForeignKey('Customer', on_delete=models.CASCADE)
is_seller = models.BooleanField(default=False)
is_customer = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
last_login = models.DateTimeField(null=True, blank=True)
date_joined = models.DateTimeField(auto_now_add=True)
USERNAME_FIELD = 'email'
EMAIL_FIELD = 'email'
REQUIRED_FIELDS = []
objects = UserManager()
I want 2 users (seller and customer). A seller can request for a customer account as well (so same email will be used for login and signup) and vice versa. what will be the best approach to this kind of scenario?
As there will be different data fields for sellers and customers, and users should be able to switch between buyer and seller profiles.
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
USER_ROLES = (
('buyer', 'Buyer'),
('seller', 'Seller'),
)
role = models.CharField(max_length=20, choices=USER_ROLES)
# Additional fields for sellers
shipping_address = models.CharField(max_length=100, blank=True)
You'll also need to handle permissions and access control based on the user's role. For example, only sellers should be able to access seller-specific features such as managing products and viewing other sellers' profiles.