Django Concurrency

Overview

Test status Coverage https://pypip.in/v/django-concurrency/badge.png Downloads Requirements Status

django-concurrency is an optimistic locking library for Django Models

It prevents users from doing concurrent editing in Django both from UI and from a django command.

Note

django-concurrency requires Django >= 1.4

How it works

Overview

django-concurrency works adding a concurrency.fields.VersionField to each model, each time a record is saved the version number changes (the algorithm used depends on the implementation of concurrency.fields.VersionField used (see Fields).

django-concurrency use two different way to manage concurrent updates:

Protocols

django 1.4 - 1.5

When a record is saved, django-concurrency tries to get a lock on the record based on the old revision number, if the record is not found a RecordModifiedError is raised. The lock is obtained using SELECT FOR UPDATE and it’s requirend to prevent other updates during the internal django save() execution.

django >= 1.6

Full implementation of optimistic-lock pattern using a SQL clause like:

UPDATE mymodel SET version=NEW_VERSION, ... WHERE id = PK AND version = VERSION_NUMBER