【发布时间】:2020-01-28 18:39:48
【问题描述】:
我正在探索 django 中的模型,我正在尝试为电子商务产品创建模型。我设计的模式现在如下
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=80)
def __str__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=100)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
total_stock = models.PositiveIntegerField(default=0)
def __str__(self):
return self.name
class Attribute(models.Model):
'''
attribute can be like color, material, size and many more
'''
name = models.CharField(max_length=80)
def __str__(self):
return self.name
class AttributeValue(models.Model):
'''
Values for the selected attribute like for size attr
the values can be Large, Medium, Small and etc
'''
name = models.CharField(max_length=100)
attribute = models.ForeignKey(Attribute, on_delete=models.CASCADE)
price = models.DecimalField(decimal_places=2, max_digits=10)
discount = models.DecimalField(decimal_places=2, max_digits=10)
stock = models.PositiveIntegerField(default=0)
def __str__(self):
return self.name
class ProductAttribute(models.Model):
'''
Associate Particular attribute to Particular product
'''
product = models.ForeignKey(Product, on_delete=models.CASCADE)
attribute = models.ForeignKey(Attribute, on_delete=models.CASCADE)
def __str__(self):
return self.product.name
class ProductImage(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
image = models.ImageField(upload_to = 'pic_folder/')
def __str__(self):
return self.product.name
我的问题是,当我研究可扩展的电子商务产品设计(在更好的表格关系和涵盖电子商务中的大部分因素方面可扩展)时,我看到了各种表格,例如
ProductVariant、ProductVariantImage、ProductOptions 等等。所以我对这些术语感到困惑。谁能帮助我通过示例让我理解这一点,我如何在models.py 中调整这些表格?
这是链接
【问题讨论】:
-
你能分享你正在谈论的链接吗?
-
我已经分享了图片链接@CalebGoodman。
-
那张图片是从哪里来的?我以为你在谈论一篇解释电子商务数据库设计的文章。
标签: python django django-models database-design