django-optimistic-admin-pg providing mixins for implementing optimistic concurrency in Django using PostgreSQL
Project description
django-optimistic-admin-pg
This app provides a couple of mixins to implement optimistic concurrency in the Django admin leveraging PostgreSQL specific features.
PostgreSQL implements an MVCC concurrency model, that means that rows are duplicated on update. PostgreSQL stores an id on each row to store the transaction identifier called xmin.
This application provides mixins for Django ModelForm and ModelAdmin using the xmin value to inhibit the saving of data via the Django admin if it has been updated in the meantime.
Notes on safety
Please note that this application does not remove completely the races between updates via the admin interfaces but it narrows them by a lot.
Similar Projects
django-concurrency implements the same pattern with batteries included in a database-independent way.
Requirements
The app is tested on Python 3.8+ with Django 3.2 and 4.0.
Setup
python -m pip install django-optimistic-admin-pg
How to use
This application provides a couple of mixins: one for ModelAdmin instances and one for ModelForm instances.
First a ModelForm inheriting from OptimisticAdminModelFormMixin should be used as form the
ModelAdmin.
A field called row_version should be added to this form in order to send the row version read
from the database.
Assuming you have forms in forms.py
:
from django import forms
from optimisticadmin.mixins import OptimisticAdminModelFormMixin
class MyModelForm(OptimisticAdminModelFormMixin, forms.ModelForm):
row_version = forms.IntegerField(required=False, widget=forms.HiddenInput())
Then in admin.py
your ModelAdmin need to inherit from OptimisticAdminMixin and use the form
implemented before:
from django.contrib import admin
from optimisticadmin.mixins import OptimisticAdminMixin
from .forms import MyModelForm
@admin.register(MyModel)
class MyModelAdmin(OptimisticAdminMixin, admin.ModelAdmin):
form = MyModelForm
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-optimistic-admin-pg-1.0.0.tar.gz
.
File metadata
- Download URL: django-optimistic-admin-pg-1.0.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbee6a3fe4c01b4809b33c790ff1052d2d407b53985b8d94f3ff31d0c9e0abc6 |
|
MD5 | f1b32b16bc161d511ca2b28d02b7ef2e |
|
BLAKE2b-256 | ddfc4e30f069cefa4d66d0e9d127af68efc339c338296bfc7225e70a52237031 |
File details
Details for the file django_optimistic_admin_pg-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: django_optimistic_admin_pg-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 349c5f2af79fcda1013ae4b33e56158016f095cd65640e69a2f489c43cc337f4 |
|
MD5 | 51063818e82875ecebf4e9745c5c45b3 |
|
BLAKE2b-256 | 90c3699700f5d71f5fef6c6763fb75919c7b29ab99252868907e1f8b63b76ab9 |