我正在创建一个包含两个表customer和seller的数据库,它们都是从使用Django auth user的user表继承而来的。我的问题是,用户是否有可能同时既是客户又是卖家?
class BaseUser(models.Model):
# have common fields
is_seller = models.BooleanField()
is_customer = models.BooleanField()
class Meta:
abstract = True
class Customer(BaseUser):
# have customer specific fields
class Seller(BaseUser):
# have seller specific fields 发布于 2018-08-03 19:11:11
对于您提到的当前模式,答案是否定的,但您可以
class BaseUser(models.Model):
# have common fields
class Meta:
abstract = True
class Customer(BaseUser):
# have customer specific fields
class Meta:
abstract = True
class Seller(BaseUser):
# have seller specific fields
class Meta:
abstract = True
# this way your user can either inherit customer or seller or both
class User(Seller):
pass
#OR
class User(Buyer):
pass
#OR
class User(Seller, Buyer):
pass发布于 2018-08-03 19:12:25
是的,你可以有另一个模型,例如Entity,它与客户和卖家有一对一的关系
class Entity(models.Model):
customer = models.OneToOneField(Customer)
seller = models.OneToOneField(Seller)现在,你可以使用这个模型,或者自定义用户模型,任何你想要的。
https://stackoverflow.com/questions/51671028
复制相似问题