Hi,
I read that we can overwrite the save() for any model to do something
before/after its save. But my issue is, how can I be sure that what i
save + what the model needs to save happen as a transaction, so if
either fails, the whole thing fails.
Example. I want to keep a total inventory count in a model called
"Item". I want to then be able to add entries in model ItemEntry,
which has a count_used. When the ItemEntry model is being saved, I
want to deduct the amount from the total in corresponding "Item"
model. But if I do something like:
# forgive the syntax, I'm winging it right now
class ItemEntry(models.Model):
....
def save():
i = Item.objects.get(pk=5)
i.count = i.count - used_value
i.save()
self.save()
if either fails in the "save()", the data will be out of sync. Is
there a way to wrap this in a "transaction", without going into the
database itself and creating triggers, etc.?
Can I specify trigger like behaviour in the model definition? I would
like to not have changes in some other place(e.g. DB), since django's
advantage is centrally organizing things.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.