A Django app for adding object tools for models in the admin
Project description
dj-obj-update is a module that helps you do two things while updating an object:
Only do a save if something changed
Log what changed (the logger name is obj_update and only outputs DEBUG)
Installation
pip install dj-obj-update
Usage
Updating an object
from obj_update import obj_update new_data = { 'flavor': 'chocolate', } for obj in queryset: obj_update(obj, new_data)
Replacement for update_or_create
from obj_update import obj_update_or_create choice, created = obj_update_or_create( Choice, question=question, defaults={'choice_text': 'Flour or corn?'}, )
https://docs.djangoproject.com/en/1.8/ref/models/querysets/#update-or-create
Logging changes
Using python-json-logger:
import logging from pythonjsonlogger.jsonlogger import JsonFormatter logger = logger.getLogger('obj_update') handler = logging.FileHandler('log/my_obj_changes.log') handler.setFormatter(JsonFormatter()) logger.addHandler(handler) logger.setLevel(logging.DEBUG)
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
dj-obj-update-0.2.1.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for dj_obj_update-0.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a26150b53bed44ec187184655594700dd3019f9fc77d79e81d5fdf8d3020d1d |
|
MD5 | ee1866dcb543d7b8390b09d0955750be |
|
BLAKE2b-256 | b9df03f1686f5ee748c0aeb4c8b9cac965fd45eeb9c52d4f96b6e6af23422a3f |