Re: Updating a model instance with extra checks.

2012-08-21 Thread Thomas Orozco
I think you could always send the signals yourself. Wrap that along in a model method, and I don't see any issue with using the manager! Le 21 août 2012 10:18, "Sebastien Flory" a écrit : > That was my idea too, but using this way, the pre_save / post_save signals > wont be triggered. > It seem

Re: Updating a model instance with extra checks.

2012-08-21 Thread Kurtis Mullins
I remember running into similar situations in a different domain (collision detection in physics engines). It was a pain in the butt :) I'd say first, figure out what you want to do if the process does reach a point where there isn't sufficient funds to perform the transaction. Then take multiple s

Re: Updating a model instance with extra checks.

2012-08-21 Thread Sebastien Flory
That was my idea too, but using this way, the pre_save / post_save signals wont be triggered. It seems strange to me to be using the objects manager instead of the model instance directly, no? Seb Le mardi 21 août 2012 02:11:42 UTC+2, Thomas Orozco a écrit : > > As a followup to the suggestion

Re: Updating a model instance with extra checks.

2012-08-20 Thread Thomas Orozco
As a followup to the suggestion of MyModel.objects.filter(money__gte = value, pk = self.pk).update(F...) Here's an example: We have testapp/models.py: from django.db import models class TestModel(models.Model): balance = models.IntegerField() >>> from django.db.models import F >>> TestMod

Re: Updating a model instance with extra checks.

2012-08-20 Thread Thomas Orozco
I think I didn't make what I meant clear enough: What do you think about the following: . Insert record . Calculate balance by summing all records before (including) the one you just inserted (and I think you will agree this is not an extremely complex query) . If balance is positive, it's approv

Re: Updating a model instance with extra checks.

2012-08-20 Thread Melvyn Sopacua
On 20-8-2012 19:37, Thomas Orozco wrote: > Circumvent the problem with smarter design: don't store the money on the > object, make the user's money the sum of all their transactions (credit - > debit). > You get lesser performance, but you also get history! This does not circumvent the problem bu

Re: Updating a model instance with extra checks.

2012-08-20 Thread Thomas Orozco
A few suggestions : Circumvent the problem with smarter design: don't store the money on the object, make the user's money the sum of all their transactions (credit - debit). You get lesser performance, but you also get history! Maybe you could try (not sure about that): MyModel.objects.filter(m

Re: Updating a model instance with extra checks.

2012-08-20 Thread Alexis Roda
Al 20/08/12 18:53, En/na Sebastien Flory ha escrit: Hi everyone, I'm looking for the proper django way to do an update of an attribute on my model instance, but only if the attribute current value is checked agains't a condition, in an atomic way, something like this: def use_money(self, value)