Skip to main content

Tracking dirty fields on a Django model instance.

Project description

Join the chat at https://gitter.im/romgar/django-dirtyfields Published PyPI version Github Actions Test status Coveralls code coverage status Read the Docs documentation status

Tracking dirty fields on a Django model instance. Dirty means that field in-memory and database values are different.

This package is compatible and tested with the following Python & Django versions:

Django

Python

2.2, 3.0, 3.1

3.9

3.2, 4.0

3.9, 3.10

4.1

3.9, 3.10, 3.11

4.2

3.9, 3.10, 3.11, 3.12

5.0

3.10, 3.11, 3.12

5.1

3.10, 3.11, 3.12, 3.13

Install

$ pip install django-dirtyfields

Usage

To use django-dirtyfields, you need to:

  • Inherit from DirtyFieldsMixin in the Django model you want to track.

from django.db import models
from dirtyfields import DirtyFieldsMixin

class ExampleModel(DirtyFieldsMixin, models.Model):
    """A simple example model to test dirty fields mixin with"""
    boolean = models.BooleanField(default=True)
    characters = models.CharField(blank=True, max_length=80)
  • Use one of these 2 functions on a model instance to know if this instance is dirty, and get the dirty fields:

    • is_dirty()

    • get_dirty_fields()

Example

>>> model = ExampleModel.objects.create(boolean=True,characters="first value")
>>> model.is_dirty()
False
>>> model.get_dirty_fields()
{}

>>> model.boolean = False
>>> model.characters = "second value"

>>> model.is_dirty()
True
>>> model.get_dirty_fields()
{'boolean': True, "characters": "first_value"}

Consult the full documentation for more information.

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_dirtyfields-1.9.5.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

django_dirtyfields-1.9.5-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file django_dirtyfields-1.9.5.tar.gz.

File metadata

  • Download URL: django_dirtyfields-1.9.5.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for django_dirtyfields-1.9.5.tar.gz
Algorithm Hash digest
SHA256 c316ab2e12cfc9da16e714007f0b313d35c3216f6b90b7b1d66c50bf1f4f3f19
MD5 1daf5fdef580c16f3eddb2dbf94d3772
BLAKE2b-256 7cc65f9a642ad623f8a66e538aadfa002a99561e794b20539575ac50c72bfda3

See more details on using hashes here.

File details

Details for the file django_dirtyfields-1.9.5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dirtyfields-1.9.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d544e648df2f13256683c3e20b93f61672b63087acf3f81ee8cedb4b0482a8c1
MD5 1ff16e680227eca4038c73b2b89a8e26
BLAKE2b-256 503398b2d301e9167ca5bca286a2a153d0640a49e96fdb584e77cecf726afbd6

See more details on using hashes here.

Supported by

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