Practical Django model utilities.
Project description
django-openutils
Practical Django model utilities. Currently ships ModelDiffMixin for tracking field changes.
Installation
pip install django-openutils
ModelDiffMixin
A model mixin that tracks field changes via __dict__ snapshotting. Uses concrete field attnames (e.g. author_id not author) so FK fields are compared by PK value without extra DB queries. Deferred fields are excluded from tracking.
Usage
from django.db import models
from django_openutils.mixins import ModelDiffMixin
class MyModel(ModelDiffMixin, models.Model):
name = models.CharField(max_length=100)
email = models.EmailField()
obj = MyModel.objects.create(name="Alice", email="alice@example.com")
obj.has_unsaved_changes # False
obj.name = "Bob"
obj.has_unsaved_changes # True
obj.unsaved_fields # dict_keys(['name'])
obj.get_unsaved_field_diff("name") # ('Alice', 'Bob')
obj.save()
obj.has_unsaved_changes # False
obj.has_updated_fields # True
obj.recent_updates # {'name': ('Alice', 'Bob')}
API
| Property / Method | Description |
|---|---|
unsaved_changes |
Dict of {field: (old, new)} for in-memory changes not yet saved |
has_unsaved_changes |
True if any fields differ from the last save/load |
unsaved_fields |
Keys of unsaved_changes |
get_unsaved_field_diff(field) |
Returns (old, new) tuple or None |
recent_updates |
Dict of {field: (old, new)} from the last save() call |
has_updated_fields |
True if recent_updates is non-empty |
updated_fields |
Keys of recent_updates |
License
MIT - see LICENSE for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_openutils-0.1.0.tar.gz.
File metadata
- Download URL: django_openutils-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51d6a04bb5f1506952cc67d45699bc0eb4e1d9e2de1f3c5faa39b0daf68f263e
|
|
| MD5 |
aad30a2b04604d7add3f1de90caab685
|
|
| BLAKE2b-256 |
bdcd52b81297306ce477001c5f9db034a40797808d272acef194f0782a8d0089
|
Provenance
The following attestation bundles were made for django_openutils-0.1.0.tar.gz:
Publisher:
publish.yml on frankapps-io/django-openutils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_openutils-0.1.0.tar.gz -
Subject digest:
51d6a04bb5f1506952cc67d45699bc0eb4e1d9e2de1f3c5faa39b0daf68f263e - Sigstore transparency entry: 991750064
- Sigstore integration time:
-
Permalink:
frankapps-io/django-openutils@254be144c0c7c30a8e8d363f09b938e4357848e8 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/frankapps-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@254be144c0c7c30a8e8d363f09b938e4357848e8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_openutils-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_openutils-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b32cee59d8f915f0e04e3db5a150af22d333570c763b33055074ef500203a37f
|
|
| MD5 |
eaa108a4f0bc33b5ca1fd6723ed8e9e7
|
|
| BLAKE2b-256 |
c70e9c8cfa6401979a85c23279f17f5bb4fababbf8cc695f583ea99a3dc8a289
|
Provenance
The following attestation bundles were made for django_openutils-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on frankapps-io/django-openutils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_openutils-0.1.0-py3-none-any.whl -
Subject digest:
b32cee59d8f915f0e04e3db5a150af22d333570c763b33055074ef500203a37f - Sigstore transparency entry: 991750069
- Sigstore integration time:
-
Permalink:
frankapps-io/django-openutils@254be144c0c7c30a8e8d363f09b938e4357848e8 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/frankapps-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@254be144c0c7c30a8e8d363f09b938e4357848e8 -
Trigger Event:
push
-
Statement type: