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.
django-concurrency requires Django >= 1.4
- easy to add to existing Models (just add concurrency.fields.VersionField )
- works with third-party models (see apply_concurrency_check())
- works with Django internal models
- handle http post and standard python code (ie. django management commands)
- complete test suite (Test suite)
- works with South and diango-reversion
- Admin integration. Handle actions and list_editable (solves issue #11313)
- can handle external updates (see TriggerVersionField)
How it works¶
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:
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.