A model that tracks model fields' values.
Project description
Django Diffable
About
A django abstract model that tracks model fields' values and provide some useful api to know what fields have been changed.
Install
pip install django-diffable
Usage
Inherit from DiffableModel:
from diffable.models import DiffableModel
from django.db import models
class Product(DiffableModel):
name = models.CharField(max_length=30)
Use as follows:
>>> product = Product(name='Atari')
>>> product.has_changed
False
>>> product.changed_fields
[]
>>> product.name = 'Commodore'
>>> product.has_changed
True
>>> product.changed_fields
['name']
>>> product.diff
{'name': ('Atari', 'Commodore')}
>>> product.get_field_diff('name')
('Atari', 'Commodore')
>>> product.save()
>>> product.has_changed
False
>>> product.name = 'ZX Spectrum'
>>> product.has_changed
True
>>> product.refresh_from_db()
>>> product.has_changed
False
>>> product.name
'Commodore'
License
The Django Wicked Historian package is licensed under the FreeBSD License.
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
django-diffable-1.0.0.tar.gz
(4.7 kB
view hashes)
Built Distribution
Close
Hashes for django_diffable-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 055775f8e229521889f816bcb52303989db098e8e0276f9157e024292f140a7c |
|
MD5 | 85837020eb8a74fd2766d76f53d6678f |
|
BLAKE2b-256 | f957ab83e9c4fd6385f3c5afdfdd4c963a53211239ea3c7cf5f58476ecbbd05c |