Skip to main content

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)


pip install dj-obj-update


Updating an object

from obj_update import obj_update

new_data = {
    'flavor': 'chocolate',
for obj in queryset:
    obj_update(obj, new_data)

Dry run updating an object

from obj_update import obj_update

logger.setLevel(logging.DEBUG)  # see "Logging changes" below

new_data = {
    'flavor': 'chocolate',
for obj in queryset:
    obj_update(obj, new_data, save=False)

Replacement for update_or_create

from obj_update import obj_update_or_create

choice, created = obj_update_or_create(
    defaults={'choice_text': 'Flour or corn?'},

Logging changes

Using python-json-logger:

import logging
from pythonjsonlogger.jsonlogger import JsonFormatter

logger = logging.getLogger('obj_update')
handler = logging.FileHandler('log/my_obj_changes.log')

With JSON logging, you’ll get messages like:

{"message": "[text hello->hello2]", "model": "FooModel", "pk": 1, "changes": {"text": {"old": "hello", "new": "hello2"}}}

With a normal logger, you’ll still get output, but it won’t have as much information:

[text hello->hello2]

Project details

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


History Node


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.4.0-py2.py3-none-any.whl (3.3 kB) Copy SHA256 hash SHA256 Wheel 3.6 Apr 19, 2018
dj-obj-update-0.4.0.tar.gz (3.2 kB) Copy SHA256 hash SHA256 Source None Apr 19, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page