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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for django_dirtyfields-1.9.7.tar.gz
Algorithm Hash digest
SHA256 23cde794612499e8b5e0f840a1c389a6fd666fcc9c01e82299fcd8ba90af151b
MD5 61bdb745c8bef2ff2a09a80c138e06d8
BLAKE2b-256 a2f6800c94ff7312b6aed9e3763f07acdb71b1bf457dd4a602de24d888104550

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_dirtyfields-1.9.7-py3-none-any.whl
Algorithm Hash digest
SHA256 084957fb8db092c05814ce92dc34276d52a0056e09a55b090bdab29f98eacc53
MD5 49319fb6a9d446146e71ec2d5b82165b
BLAKE2b-256 4934e3095c10f3d6838329d11ecce36d8136bfe553b4e960cb10f1fcca434841

See more details on using hashes here.

Supported by

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