Detect field change in Django model

Viewed 9317

Is it possible to detect that field in Django model has been changed?

class Product(models.Model):
    my_current_price = MoneyField(max_digits=20, decimal_places=2, null=True, blank=True,
                                  verbose_name=_('My original price'))
    my_eur_price = MoneyField(max_digits=20, decimal_places=2, null=True, blank=True, verbose_name=_('My price in EUR'))
    my_usd_price = MoneyField(max_digits=20, decimal_places=2, null=True, blank=True, verbose_name=_('My price in USD'))

The thing is that I need to recalculate EUR and USD price anytime when my_current_price is changed.

I have two ideas:

  1. Somehow override MoneyField and send signal when the field is changed.

  2. Override save method and create a new attribute __my_current_price like here - this works but it makes code very unclear for me.

EDIT: I store the price in different currencies because of faster database lookups.

1 Answers
Related