I'm wondering if there's any way to handle concurrent modification of
data in a django application.
Say I have a class:
==========
class ViewCount(models.Model):
object = models.ForeignKey(Foo)
count = models.IntegerField(default=0)
==========
I'd like to be able to do something like:
==========
def incrementCount(target_count):
target_count.count = target_count.count + 1
target_count.save()
==========
Conceptually, if multiple servers are running, and 2+ try to update the
count at the same time, it's possible that the new total would be
incorrect. (For completeness: A reads 0, A writes 1, B reads 1, C reads
1, C writes 2, B writes 2... count is 2 but should be 3)
Does Django have an integrated solution to this sort of problem?
If not, does the community have a 'best practice' for dealing with
this?
Thanks!
--Ben
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---