Skip to main content

Lock your model instances to prevent their unintended modification or deletion.

Project description

Django Object Lock

Oops! I think I've edited the wrong object.

We don't need to edit this any longer. I wish I could prevent this object from being edited anymore...

Django Object Lock (django-object-lock) adds a "locked" status to your models to prevent their unintentional modification or deletion from your Django admin site, your API or any view. You can "lock" an instance to protect it and then "unlock" it to allow further modifications or deletions.

Check out the documentation for more information.

Features

  • A lock icon will appear in the changelist for each locked instance.

    Locked articles

    The detail page for a locked object will be read-only.

    Locked article detail

  • This "locked" status may be set manually (adding a field for your users to lock or unlock the object) or automatically (locking objects depending on a condition).

    For example, you can have a parent model that can be locked setting manually a Boolean field and a child model that will be automatically locked or unlocked whenever its parent is.

    Locked article sections

    This way, you can lock and unlock entire hierarchies of model instances.

Support

django-object-lock is tested with the following versions of Python and Django:

  • Python >= 3.8
  • Django 4 or 5
  • Django REST Framework >= 3.14 (to enforce object locking from your API generic views and viewsets)

Django is the only required dependency.

Development instructions

You can find a demo project and a test suite in the demo directory.

The demo project contains three lockable models:

  • an Article model,
  • a child ArticleSection model, and
  • a NotLockedModel that is registered in the admin as a lockable model, but it does not have locking logic.

You will need to install development dependencies in your Python environment:

pip install -r requirements-dev.txt

Then, run the demo application:

cd demo && python manage.py runserver

Or run tests with Tox:

# Test for Python 3.12, Django 5.0 and Django REST Framework 3.14.
tox -e py3.12-django5.0-drf3.14

# Generate a coverage report.
tox -e coverage

# Check PEP8 compliance.
tox -e flake8

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-lock-1.0.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_object_lock-1.0.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file django-object-lock-1.0.0.tar.gz.

File metadata

  • Download URL: django-object-lock-1.0.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for django-object-lock-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2ba65327e83bdaaee9704e29c23234856ec6c75dfa153fc7ddbdd709b6549105
MD5 734c1a3406b2485d2179b66919cc093b
BLAKE2b-256 aa0005c803567a6bb1a98616d8dfb217692f9c83568f6420a4828d48f72bb2b5

See more details on using hashes here.

File details

Details for the file django_object_lock-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_object_lock-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7ba76ca4a9c955d079d8839a8d3851b23094d1844a243dba1e3133b42070954
MD5 1eaf939c105b227737be3b4aa9a6c186
BLAKE2b-256 31f1667be6c6df7729c3e8a7bc0079f5b2d16ff518c1ab2905703264936c15bf

See more details on using hashes here.

Supported by

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