【问题标题】:schema design for ecommerce product电子商务产品的架构设计
【发布时间】: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

我的问题是,当我研究可扩展的电子商务产品设计(在更好的表格关系和涵盖电子商务中的大部分因素方面可扩展)时,我看到了各种表格,例如 ProductVariantProductVariantImageProductOptions 等等。所以我对这些术语感到困惑。谁能帮助我通过示例让我理解这一点,我如何在models.py 中调整这些表格?

这是链接

https://i.imgur.com/qGDBz29.png

【问题讨论】:

  • 你能分享你正在谈论的链接吗?
  • 我已经分享了图片链接@CalebGoodman。
  • 那张图片是从哪里来的?我以为你在谈论一篇解释电子商务数据库设计的文章。

标签: python django django-models database-design


【解决方案1】:

我认为您只是想了解这些术语以及它们之间的关系,对吗?一旦你理解了,你就可以决定如何调整架构和模型。

ProductVariant:产品的“版本”。从电子商务的角度来看,这可能意味着某些东西不完全适合 AttributeAttributeValue 模型。例如,一个产品可以有一个变体:

  • 尺寸
  • 原产国
  • 语言
  • 仅限男性,仅限女性,男女皆宜
  • 不同的价格点(高端与低端,公共与私人)

我认为您可以不使用 ProductVariant 模型,而只需使用属性即可。使用 ProductVariant 作为对预先存在的 Product 的引用(Product.id 的外键约束)可能是有意义的。请参阅herehere

ProductVariantImageProductImage的一个版本。

ProductOptions:产品的选项。您可以只使用 Attributes 代替。此表/模型似乎与 AttributesAttributeValues 已有的没有任何不同。

【讨论】:

  • 您是说产品可以有不同的尺寸。是不是尺寸因素进入属性?对不起,如果我误解了。可以举个服装产品的例子吗?
  • 当然。你是对的 size 被存储为属性。这可能是我最初设计模型的方式。但是,它也可以定义为产品变型。产品变体只是意味着您的产品可以呈现给客户的另一种方式。尺寸是典型的产品变体,因为同一产品可以以多种不同尺寸出售。请参阅他们在ithemes.com/ecommerce-product-variants-101 提供的示例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-07
  • 2019-02-22
  • 2020-06-08
  • 1970-01-01
  • 2017-12-16
  • 1970-01-01
相关资源
最近更新 更多