Fields

VersionField

class concurrency.fields.VersionField(*args, **kwargs)[source]

Base class

IntegerVersionField

class concurrency.fields.IntegerVersionField(*args, **kwargs)[source]

Version Field that returns a “unique” version number for the record.

The version number is produced using time.time() * 1000000, to get the benefits of microsecond if the system clock provides them.

AutoIncVersionField

class concurrency.fields.AutoIncVersionField(*args, **kwargs)[source]

Version Field increment the revision number each commit

TriggerVersionField

class concurrency.fields.TriggerVersionField

This field use a database trigger to update the version field. Using this you can control external updates (ie using tools like phpMyAdmin, pgAdmin, SQLDeveloper). The trigger is automatically created during syncdb() or you can use the triggers management command management command.

Warning

Before django-concurrency 1.0 two triggers per field were created,

if you are upgrading you must manually remove old triggers and recreate them using :ref:`triggers`_ management command

trigger_name

TriggerVersionField.trigger_name

Starting from 1.0 you can customize the name of the trigger created. Otherwise for each TriggerVersionField will be created two triggers named:

'concurrency_[DBTABLENAME]_[FIELDNAME]'

Warning

Any name will be automatically prefixed with concurrency_

triggers management command

Helper command to work with triggers:

  • list : list existing triggers for each database
  • drop : drop exisitng triggers
  • create : create required triggers

example

sax@: (concurrency) django-concurrency [feature/triggers*] $ ./demo/manage.py triggers create
DATABASE             TRIGGERS
default              concurrency_concurrency_triggerconcurrentmodel_u

ConditionalVersionField

This field allow to configure which fields trigger the version increment so to limit the scope of the concurrency checks.

class User(models.Model):
    version = ConditionalVersionField()
    username = models.CharField(...)
    password = models.PasswordField(...)

    class ConcurrencyMeta:
        check_fields = ('username',)