jiazou/4bp — comment on commit fa22fea2562c59d57b42e69c5deac2146636a607
File: Abp/base_model/models.py line 50
By zhanghao8301:

This together with the price field in class ProductPricesHistory would be assuming everything has a same local_currency_value? Money class is a kind of "Singleton", unless you want to associate each row with a product ID? If yes, can we merge this into the ProductHistory model then?

We need to distinguish prices among products, but don't want to create a different table for each product.

To make it clearer, and for ease of reference in future, I would recommend storing historical prices in a dictionary, as in:
{"datetime": "usd_price"} format. We can define a customized field (basically a serialized string) to realize this.

For example:
class SerializedDataField(models.TextField):
__metaclass__ = models.SubfieldBase

def to_python(self, value):
if value is None: return
if not isinstance(value, basestring): return value
value = pickle.loads(base64.b64decode(value))
return value

def get_db_prep_save(self, value):
if value is None: return
return base64.b64encode(pickle.dumps(value))

See reference https://docs.djangoproject.com/en/dev/howto/custom-model-fields/

And then we can store whatever format we want, including dictionary and list.

I'm also thinking since this is the start, we are primarily focusing on US market.

We can keep a table called ForeignExchangeRates, with all foreign exchange rates w.r.t USD. Then in the ProductPriceHistory, we can just store three fields related to price: "currency", "local_currency_value", and "usd_value". We can then run a cron job everyday to update the usd_value.