I'm new on django. I'm making the simple inventory application. Here's my Model:
我是django的新手。我正在制作简单的库存应用程序。这是我的模型:
class Received(models.Model):
item = models.ForeignKey(Item)
weight = models.DecimalField(max_digits=8, decimal_places=2)
....
class Sold(models.Model):
item = models.ForeignKey(Item)
weight = models.DecimalField(max_digits=8, decimal_places=2)
....
class Inventory(models.Model):
item = models.OneToOne(Item)
weight_received = ?
weight_sold = ?
timestamp = models.DateTimeField()
....
class InventoryHistory(models.Model):
# I have no idea
item = models.ForeignKey(Item)
date = models.DateField(auto_now=True)
total_weight = models.DecimalField(max_digits=8, decimal_places=2)
What I wanna do is when:
我想做的是:
1.) I do an input data on Received
or Sold
the Inventory
should automatically update (where Inventory.weight_in
is SUM of Received.weight
and Inventory.weight_out
is SUM of Sold.weight
.)
1.)我做一个关于Received或Sold the Inventory的输入数据应该自动更新(其中Inventory.weight_in是Received.weight的SUM,而Inventory.weight_out是Sold.weight的SUM。)
2.) I do a delete on them, Inventory
should be automatically update
2.)我对它们进行删除,库存应该自动更新
3.) I do en edit on them, Inventory
should be automatically update
3.)我对它们进行编辑,库存应该自动更新
Is it possible, and how?
是可能的,怎么样?
And here's another one question about my lack of database knowledge problem. Is it necessary to me to make a InventoryHistory
where I can track a history of inventory in daily?
这是另一个关于我缺乏数据库知识问题的问题。我是否有必要创建一个InventoryHistory,我可以在其中跟踪每日的库存历史记录?
Thank you...
1 个解决方案
#1
0
You can use signals. In particular django.db.models.signals.post_save
and django.db.models.signals.post_delete
. For tracking history I recommend to use django-reversion.
你可以使用信号。特别是django.db.models.signals.post_save和django.db.models.signals.post_delete。对于跟踪历史记录,我建议使用django-reversion。
#1
0
You can use signals. In particular django.db.models.signals.post_save
and django.db.models.signals.post_delete
. For tracking history I recommend to use django-reversion.
你可以使用信号。特别是django.db.models.signals.post_save和django.db.models.signals.post_delete。对于跟踪历史记录,我建议使用django-reversion。