Unable to import data ?

Sometimes you need to temporary disable concurrency (ie during data imports)

Temporary disable per Model

from concurrency.api import disable_concurrency

with disable_concurrency(instance):

Add version management to new models

from concurrency.fields import IntegerVersionField

class ConcurrentModel( models.Model ):
    version = IntegerVersionField( )

a = ConcurrentModel.objects.get(pk=1)
b = ConcurrentModel.objects.get(pk=1) # this will raise ``RecordModifiedError``

Add version management to Django and/or plugged in applications models

Changed in version 0.8.

Concurrency can work even with existing models, anyway if you are adding concurrency management to an existing database remember to edit the database’s tables:

from django.contrib.auth import User
from concurrency.api import apply_concurrency_check

apply_concurrency_check(User, 'version', IntegerVersionField)

If used with Django>=1.7 remember to create a custom migration.

Test Utilities

ConcurrencyTestMixin offer a very simple test function for your existing models

from concurrency.utils import ConcurrencyTestMixin
from myproject.models import MyModel

class MyModelTest(ConcurrencyTestMixin, TestCase):
    concurrency_model = TestModel0
    concurrency_kwargs = {'username': 'test'}

Recover deleted record with django-reversion

Recovering deleted records with diango-reversion produces a RecordModifiedError, because both pk and version are present in the object, and django-concurrency tries to load the record (that does not exist), which raises RecordModifiedError then.

To avoid this simply disable concurrency, by using a mixin:

class ConcurrencyVersionAdmin(reversion.admin.VersionAdmin):

    def revision_view(self, request, object_id, version_id, extra_context=None):
        return super().revision_view(request, object_id, version_id, extra_context=None)

    def recover_view(self, request, version_id, extra_context=None):
        return super().recover_view(request, version_id, extra_context)