Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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:

  1. Only do a save if something changed
  2. 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)

Release History

This version
History Node

0.2.1

History Node

0.2.0

History Node

0.1.0

History Node

0.0.0

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
dj_obj_update-0.2.1-py2.py3-none-any.whl
(4.5 kB) Copy SHA256 Hash SHA256
Wheel 2.7 Aug 2, 2015
dj-obj-update-0.2.1.tar.gz
(2.7 kB) Copy SHA256 Hash SHA256
Source None Aug 2, 2015

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting