django model对象修改_django模型对象属性按日期跟踪更新/编辑/更改

I have a django model class e.g.

class BankAccount (model.Models):

value = models.PositiveSmallIntegerField(default=0)

I would like to edit this value and edit it on a weekly basis e.g.

wk1: value = 1

wk2: value = 30

...

wk 50: value = 70

QUESTION:

I would like to keep track of the value changes and be able to display the value for the previous weeks:

e.g. today is wk 40 and value = 60 and I would like to check what was the value in wk 30, wk 20, wk 10 etc ...

How to do this in django?

My only idea I have at the moment is to either create a new object for every other week and keep all the objects OR track the changes in the model with off-the-shelf app?

Does anybody have any better idea?

解决方案

To me it would make sense to have a transaction model with dates and times where you store each value then update the BankAccount value as appropriate.

You would apply transactions to the transactions table and update the balance/value of BankAccount.

This would be the standard way to design something like this. It also gives you a safety-net, history should something go wrong allowing a recalculation of of the value etc.

The other option is to just have a transactions model but with an additional field current_balance. This would be used to store the balance effective right after that transaction executed. Thus, the latest transaction record for a user and currency also contains their current balance.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值