Is it possible to get the original version of the object in obj_update? I need to check if a flag is being toggled to perform further processing. My code:
def obj_update(self, bundle, **kwargs):
# Update the state of all event groups for this strategy
# if required.
instance = self.obj_get(bundle, **kwargs)
# Get the original version.
original = EventStrategy.objects.get(pk=instance.pk)
print("Original: %s, %s ==> %s" % (original.name, original.active, instance.active))
# Check active state transition.
if original.active != instance.active:
print("Toggling %s" % instance.name)
# Update groups.
for group in instance.event_groups.all():
group.active = not group.active
group.updated = datetime.datetime.utcnow()
group.save()
return super(EventStrategyResource, self).obj_update(bundle, **kwargs)
When, I do a PUT and set the flag to FALSE, the output from the first print statement is:
Original: Test, True ==> True
Thanks