I am trying to make a small inventory app in a Django app. I want to be able to see the stock on hand, where it is (between two places and all together), purchase to add to inventory, and sell to reduce inventory. Tracking sales would be nice. So all in all, there are about five things I would like to do. To track the location, I was thinking of listing warehouse one as 1 and two as 2, and could query WHERE field = 1, but if I have the same product in two places, I would run into an issue. I also don't know the best way to approach it. Reading through post here, I see some people saying to just track sales, and total them in a flat db, others to remove from the db, but that would lead to discrepancies. This is my model.py so far, just really stabbing at the dark here, looking for some guidance.
我正在尝试在Django应用程序中创建一个小型库存应用程序。我希望能够看到库存,它在哪里(两个地方之间和所有地方),购买以添加到库存,并出售以减少库存。跟踪销售情况会很好。总而言之,我想做大约五件事。为了跟踪位置,我想将仓库一个列为1,将两个列为2,并且可以查询WHERE字段= 1,但如果我在两个地方有相同的产品,我会遇到问题。我也不知道接近它的最佳方法。通过这里的帖子阅读,我看到有些人说要跟踪销售情况,并将它们整合在一个平面数据库中,其他人要从数据库中删除,但这会导致差异。这是我的model.py到目前为止,只是在这里真正刺伤黑暗,寻找一些指导。
from django.db import models
class Product(models.Model):
product_ID = models.IntegerField(primary_key=True)
name = models.CharField(max_length=100)
type = (
('WHT' , 'White Wine'),
('RED' , 'Red Wine'),
('SPRT', 'Spirits'),
('BR' , 'Beer'),
)
size = (
('12' , '12oz'),
('16' , '16oz'),
('375' , '375mL'),
('750' , '750mL'),
('1' , '1L'),
)
amount_per_case = models.IntegerField()
warehouse = (
(1 , 'One'),
(2 , 'Two'),
)
on_hand = models.IntegerField()
class Store(models.Model):
store_ID = models.IntegerField(primary_key=True)
store_name = models.CharField()
store_type = (
('Supermarket', 'Supermarket'),
('Liquor Store', 'Liquor Store'),
)
store_address = models.CharField()
store_phone = models.CharField()
store_contact = models.CharField()
class Vendor(models.Model):
vendor_ID = models.IntegerField(primary_key=True)
vendor_name = models.CharField()
vendor_address = models.CharField()
vendor_phone = models.CharField()
vendor_contact = models.CharField()
class Sale(models.Model):
sale_date = models.DateField()
sale_product = models.ForeignKey(Product)
1 个解决方案
#1
1
You should make a Warehouse model and create a many-to-many relationship between Product and Warehouse, using the through
option to specify another model to hold relationship details called something like WarehouseProduct, in which you store the counts. See this section of the docs, and the following section.
您应该创建一个Warehouse模型并在Product和Warehouse之间创建多对多关系,使用through选项指定另一个模型以保存称为WarehouseProduct之类的关系详细信息,您可以在其中存储计数。请参阅文档的此部分以及以下部分。
P.S. You can do much the same thing to associate sales with particular stores, which seems to me to be something that would probably be of interest to you, as well.
附:你可以做同样的事情来将销售与特定的商店联系起来,这在我看来也是你可能感兴趣的东西。
#1
1
You should make a Warehouse model and create a many-to-many relationship between Product and Warehouse, using the through
option to specify another model to hold relationship details called something like WarehouseProduct, in which you store the counts. See this section of the docs, and the following section.
您应该创建一个Warehouse模型并在Product和Warehouse之间创建多对多关系,使用through选项指定另一个模型以保存称为WarehouseProduct之类的关系详细信息,您可以在其中存储计数。请参阅文档的此部分以及以下部分。
P.S. You can do much the same thing to associate sales with particular stores, which seems to me to be something that would probably be of interest to you, as well.
附:你可以做同样的事情来将销售与特定的商店联系起来,这在我看来也是你可能感兴趣的东西。