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:

Python

Django

3.10

3.2, 4.0, 4.1, 4.2, 5.0, 5.1, 5.2

3.11

4.1, 4.2, 5.0, 5.1, 5.2

3.12

4.2, 5.0, 5.1, 5.2, 6.0

3.13

5.1, 5.2, 6.0

3.14

5.2, 6.0

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.9.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

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

django_dirtyfields-1.9.9-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_dirtyfields-1.9.9.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_dirtyfields-1.9.9.tar.gz
Algorithm Hash digest
SHA256 c11c8e03827166d2c91f6634a4d10f5aa5cc7ea430d60e5bd576b3ebf319172f
MD5 18007bb8c5069158ef6cfec89888c06f
BLAKE2b-256 8e0d0c7d727f7f14f82450b72e5213c6ed0da3d16add2de2e59d46aea6b6eaa2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_dirtyfields-1.9.9-py3-none-any.whl
Algorithm Hash digest
SHA256 80da479ab989331e6f29c90576e5f7d7b3df65b36f16bfd6f5d37a0dbdeda6b0
MD5 c95d8f3cc893f03d65dc18fbe0bd6a5e
BLAKE2b-256 1882d274e924565c2b11eb59fadb5c95885b10502755b4f458bea477a9a6f8af

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