django-dirtyfields 0.1
pip install django-dirtyfields==0.1
Released:
Tracking dirty fields on a Django model instance
Navigation
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: BSD License (BSD)
- Author: Simon de Haan
Classifiers
- Development Status
- Framework
- Intended Audience
- License
- Operating System
- Programming Language
- Topic
Project description
Tracking dirty fields on a Django model instance.
$ pip install django-dirtyfields
or if you’re interested in developing it
$ virtualenv --no-site-packages ve/ $ source ve/bin/activate (ve)$ pip install -r requirements.pip (ve)$ python setup.py develop (ve)$ cd example_app && ./manage.py test testing_app
Makes a Mixing available that will give you the methods:
is_dirty()
get_dirty_fields()
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.get_dirty_fields() {} >>> tm.boolean = False >>> tm.is_dirty() True >>> tm.get_dirty_fields() {'boolean': True} >>> tm.characters = "have changed" >>> tm.is_dirty() True >>> tm.get_dirty_fields() {'boolean': True, 'characters': 'testing'} >>> 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.
Project details
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: BSD License (BSD)
- Author: Simon de Haan
Classifiers
- Development Status
- Framework
- Intended Audience
- License
- Operating System
- Programming Language
- Topic
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
Built Distribution
File details
Details for the file django-dirtyfields-0.1.tar.gz
.
File metadata
- Download URL: django-dirtyfields-0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f2aef3870b6c841bc537db5b8a5dc11275163a5e9320423d9fb8a826e93bb19 |
|
MD5 | 06df34007103e4712f55b6f3d8fb6a5f |
|
BLAKE2b-256 | 3936cea62ab059cadbc7406f26b7fd729dac63efad18e776fb389db2dae52313 |
File details
Details for the file django_dirtyfields-0.1-py2.6.egg
.
File metadata
- Download URL: django_dirtyfields-0.1-py2.6.egg
- Upload date:
- Size: 4.5 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23f25591027764927e525aea55c945b9855d891c66d3a15fb881c056352b67a0 |
|
MD5 | 5826efc2423bdb4b82b4b063fcc72f0e |
|
BLAKE2b-256 | 954199f8a7a71b847381387a4aef9807fe66e67a578d5231892ac0302285ba46 |