Django fieldsignals simply makes it easy to tell when the fields on your model have changed.
Project description
============
Introduction
============
.. highlightlang:: python
``django-fieldsignals`` simply makes it easy to tell when the fields on your model have changed.
Often model updates are quite expensive. Sometimes the expensive operations
are sometimes very rare. This makes it tempting to put the update logic in a view,
rather than in a save() method or in a signal receiver::
# A bad example. Don't do this!
def edit_poll(request, poll_id):
# ...
if form.cleaned_data['poll_name'] != poll.name:
poll.update_slug(form.cleaned_data['poll_name'])
poll.save()
That's a bad idea, because your model consistency is now dependent on your view.
Instead, use ``fieldsignals``::
from fieldsignals import pre_save_changed
def update_poll_slug(sender, instance, **kwargs):
instance.slug = slugify(instance.name)
pre_save_changed.connect(update_poll_slug, sender=Poll, fields=['name'])
In case you want to know what changed, ``fieldsignals`` even tells you the old and
new values of your fields::
from fieldsignals import pre_save_changed
def print_all_field_changes(sender, instance, changed_fields=None, **kwargs):
for field, (old, new) in changed_fields.items():
print "%s changed from %s to %s" % (field.name, old, new)
pre_save_changed.connect(print_all_field_changes, sender=Poll)
Installation
-----------
1. This library is on PyPI so you can install it with::
pip install django-fieldsignals
or from github::
pip install git+https://github.com/craigds/django-fieldsignals.git#egg=django-fieldsignals
2. Add "polls" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = (
...
'fieldsignals',
)
Introduction
============
.. highlightlang:: python
``django-fieldsignals`` simply makes it easy to tell when the fields on your model have changed.
Often model updates are quite expensive. Sometimes the expensive operations
are sometimes very rare. This makes it tempting to put the update logic in a view,
rather than in a save() method or in a signal receiver::
# A bad example. Don't do this!
def edit_poll(request, poll_id):
# ...
if form.cleaned_data['poll_name'] != poll.name:
poll.update_slug(form.cleaned_data['poll_name'])
poll.save()
That's a bad idea, because your model consistency is now dependent on your view.
Instead, use ``fieldsignals``::
from fieldsignals import pre_save_changed
def update_poll_slug(sender, instance, **kwargs):
instance.slug = slugify(instance.name)
pre_save_changed.connect(update_poll_slug, sender=Poll, fields=['name'])
In case you want to know what changed, ``fieldsignals`` even tells you the old and
new values of your fields::
from fieldsignals import pre_save_changed
def print_all_field_changes(sender, instance, changed_fields=None, **kwargs):
for field, (old, new) in changed_fields.items():
print "%s changed from %s to %s" % (field.name, old, new)
pre_save_changed.connect(print_all_field_changes, sender=Poll)
Installation
-----------
1. This library is on PyPI so you can install it with::
pip install django-fieldsignals
or from github::
pip install git+https://github.com/craigds/django-fieldsignals.git#egg=django-fieldsignals
2. Add "polls" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = (
...
'fieldsignals',
)
Project details
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
Close
Hashes for django-fieldsignals-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c80c4c4d5e369e9fb0c41e87c854412e0babf4c012f30a1f6ff74ebfcfd84089 |
|
MD5 | 2f3921b706a8cbad617b90ea5884a4d3 |
|
BLAKE2b-256 | 424dd0c54fb3d3066ad14cefb31889bb3f94ce8f21856c81b03995c6cb4bce0c |
Close
Hashes for django_fieldsignals-0.1.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb2536b942f599828a5d255fb320838592013bf1367074686bf5fa399d96f344 |
|
MD5 | e8608cd71acd274d5e84c1a9e90db10f |
|
BLAKE2b-256 | c0b79b51333f9d042286fc8c73cd57c914e8fafc3fa1b9641676d182a51eef46 |