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.