【问题标题】:Design Database for Billing System计费系统设计数据库
【发布时间】:2012-02-12 14:10:15
【问题描述】:

我正在尝试设计一个 django 应用程序来帮助我管理我的小商店。我希望能够以比现在更简单的方式结账,但我需要一些数据库设计方面的帮助。

现在我是这样的:

class Product(models.Model):
  name = models.CharField(max_length=200)
  price = models.IntegerField()

class Article(models.Model):
  product = models.ForeignKey(Producto)
  qty = models.IntegerField()
  id = models.AutoField(primary_key=True)

class Order(models.Model):
  number = models.CharField(max_length=20, primary_key=True)
  client = models.ForeignKey(Client)
  invent = models.ForeignKey(Invent)
  articles = models.ManyToManyField(Article)

我怀疑产品-文章的设计是否做得很好,应该有不同的方法来做到这一点,因为我的数据库中会有很多重复的数据。

还有一个问题,文章是订单“拥有”还是文章有订单“归属”,不知道问题是否明确。

编辑1:

我对产品文章的看法:

+------------------+ +----------------+ +---------- --------+ |产品 | |产品 | |文章 | |-----------------| |----------------| |-----------------| | | | | | | |姓名 | |名称

另一个问题是:

+------------------+ +-----------------+ +---------- ----+ |订购 | |订购 |文章 | |号码 | | ... | |客户 | +----------> +--------------+ VS | | | | | | | | |客户 | + 订购 | | ... | | | | | | | | | | | | ... | +---------------+ |文章 + + | | | +-----------------+ +-----------------+

【问题讨论】:

  • 您能否详细说明 “我怀疑 Product-Article 设计是否做得很好,应该有不同的方法来做到这一点,因为我的数据库中有很多重复的数据”?
  • 这里很难确定你在问什么;尝试在在您的问题标题中以不超过 15 个字的方式表达您的问题。您的问题需要更具体。
  • 我添加了一些图来更好地解释它。
  • 是这样吗?您有一个产品(例如“Lindor 糖果”)和一个文章(它是不同包装的产品)。客户正在购买文章,然后将其保存在订单中。如果是这样,价格应该在 Article 对象中。
  • +1 只是为了漂亮的 ascii 艺术

标签: database django database-design django-models


【解决方案1】:

可能是这样的:

class Product(models.Model):
  name = models.CharField(max_length=200)
  current_price = models.IntegerField()

class Order(models.Model):
  number = models.CharField(max_length=20, primary_key=True)
  client = models.ForeignKey(Client)
  invent = models.ForeignKey(Invent)
  total = models.IntegerField()

class Article(models.Model):
  product = models.ForeignKey(Product)
  order = models.ForeignKey(Order)
  qty = models.IntegerField()
  price = models.IntegerField()

也检查一下:Extra fields on many-to-many relationships

【讨论】:

  • 是的,我正在尝试讨论哪种代码更好,您拥有的或我的。谢谢
猜你喜欢
  • 2014-05-17
  • 1970-01-01
  • 2010-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-27
  • 1970-01-01
  • 2014-10-23
相关资源
最近更新 更多