Skip to main content

UNKNOWN

Project description

django-object-utils

This small library provides helpers for updating Django model objects without race conditions.

Installation

pip install django-object-utils

Usage

from django_object_utils import reload_object, update_object, lock_object

user = User.objects.get(pk=1)

# Reload object in-place with the latest version from the database
reload_object(user)

# Run SQL UPDATE for certain fields only and update the Python object
update_object(user, username='john', email='john@gmail.com')

# Run SQL UPDATE and then reload the object from the database
update_object(user, balance=F('balance')+payment, reload=True)

if request.method == 'POST':
        with transaction.atomic():
                # Enter a critical section and ensure that the object is the latest version.
                # Use the corresponding database row as the synchronization monitor.
                lock_object(user)
                form = UserForm(data=request.POST)
                form.save()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-object-utils-0.0.1.tar.gz (1.8 kB view details)

Uploaded Source

File details

Details for the file django-object-utils-0.0.1.tar.gz.

File metadata

File hashes

Hashes for django-object-utils-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3fdc672bbec1df7cbc03cf097887ae66886aac946c392b5a0772b21321402b9e
MD5 466cb1857446a1119389a2719a055fd3
BLAKE2b-256 b1b8f7223010a4fea7f72daee2c34d9871346b39ba087b5d9f6bd2498a3fdb6b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page