我正在尝试设计一个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)
我怀疑产品 - 文章设计做得好,应该采用不同的方法,因为我的数据库中会有很多重复的数据。
另一个问题是,如果该文章被订单“拥有”,或者该文章有“归属”的命令,我不知道问题是否清楚。
EDIT1:
我对产品文章的看法:
+------------------+ +----------------+ +------------------+ | Product | | Product | | Article | |------------------| |----------------| |------------------| | | | | | | | Name | | Name <--------+ Product | | | VS | | | | | Price | | | | | | | | Price | | Qty | | Qty | | | | | +------------------+ +----------------+ +------------------+
另一个问题是:
+------------------+ +-----------------+ +--------------+ | Order | | Order <-------+ Article | |------------------| |-----------------| |--------------| | Number | +--------------+ | | | | | +------------->| Article | | Number | | ... | | Client | +----------> +--------------+ VS | | | | | | | | | Client | + Order | | ... | | | | | | | | | | | | ... | +--------------+ | Articles + + | | | +------------------+ +-----------------+
答案 0 :(得分:0)
也许是这样的:
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()