我正在尝试在 Django 应用程序中制作一个小型库存应用程序。我希望能够看到手头的库存,它在哪里(在两个地方之间和一起),购买以增加库存,并出售以减少库存。跟踪销售会很好。总而言之,我想做大约五件事。为了跟踪位置,我想将仓库 1 列为 1,将仓库 2 列为 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)