MyModel.objects.update_or_create() --> Boolean wether data was updated or not?

Viewed 1139

AFAIK Django does not provide a generic way to see if data was changed by update_or_create()

The boolean created tells me that a row was created. But how can I know if data was changed (SQL UPDATE which changed data)

Example:

obj, created = MyModel.update_or_create(pk=12345,
                       defaults=dict(name='Doctor Zhivago'))

There are three cases:

  1. obj was created. No problem, I have the boolean variable created
  2. obj was not created, it was updated. For example the previous name was "Machuca".
  3. obj was not created and not updated. For example the previous name was already "Doctor Zhivago".

I can't distinguish between case2 and case3 at the moment.

3 Answers
Related