Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Django Dirty Fields

Tracking changed fields on a Django model instance.

Makes a Mixin available that will give you the properties:

  • is_dirty

  • dirty_fields

Installing

Install the package using pip. Then use the instructions in “Using the Mixin in the Model”.

$ pip install django-dirtyfields

or if you’re interested in developing it, use virtualenv. The default settings.py will look for the dirtyfields package in its current location.

$ virtualenv --no-site-packages ve/
$ source ve/bin/activate
(ve)$ cd example_app
(ve)$ pip install -r requirements.pip
(ve)$ ./manage.py test testing_app

Using the Mixin in the Model

from django.db import models
from dirtyfields import DirtyFieldsMixin

class TestModel(DirtyFieldsMixin, models.Model):
    """A simple test model to test dirty fields mixin with"""
    boolean = models.BooleanField(default=True)
    characters = models.CharField(blank=True, max_length=80)

Using it in the shell

(ve)$ ./manage.py shell
>>> from testing_app.models import TestModel
>>> tm = TestModel(boolean=True, characters="testing")
>>> tm.save()
>>> tm.is_dirty
False
>>> tm.dirty_fields
()
>>> tm.boolean = False
>>> tm.is_dirty
True
>>> tm.dirty_fields
('boolean', )
>>> tm.characters = "have changed"
>>> tm.is_dirty
True
>>> tm.dirty_fields
('boolean', 'characters', )
>>> tm.save()
>>> tm.is_dirty
False
>>> tm.get_dirty_fields
()

Why would you want this?

When using signals, especially pre_save, it is useful to be able to see what fields have changed or not. A signal could change its behaviour depending on whether a specific field has changed, whereas otherwise, you only could work on the event that the model’s save() method had been called.

Credits

This code has largely be adapted from what was made available at Stack Overflow.

Metadata

Release files for caldwell-dirtyfields 0.5b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for caldwell-dirtyfields 0.5b1
File Size Uploaded Provenance Actions
caldwell-dirtyfields-0.5b1.tar.gz 8.5 kB Without provenance Details for caldwell-dirtyfields-0.5b1.tar.gz

Release files / caldwell-dirtyfields-0.5b1.tar.gz

Download URL caldwell-dirtyfields-0.5b1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
19ff0937380da1756ec22b73682a94427874bc994aa351f17c7a8da86fd1899b
BLAKE2b-256 checksum
How to use checksums
ce1ef245ba72aa7c7fe505913229a7193dc2e9de03db445e67fbd92e682b46d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for caldwell-dirtyfields 0.5b1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5b0

0.3b1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page