Skip to main content

A reusable Django Model that allows you to storeregistre actions log of models.

Project description


django-modelwithlog is a reusable Django Abstract Model that make automatic history log of your model.

The History of all model will write in a Model RegisterLog compose of:

date and time of ocurrency

The ContentType of the concrect Model

A JSON of user and acess data loged on ocurrency

A JSON with a data of model modificate

The primary key of model

The representation of model

The action of ocurrency (ADDITION, CHANGE or DELETION)

The message of ocurrency of human read


.. code-block:: shell

pip install django-modelwithlog


.. code-block:: shell

pip install git+

Add `threadlocals.middleware.ThreadLocalMiddleware` to your `MIDDLEWARE_CLASSES` setting.

Add 'log_models' to your 'SETTINGS.INSTALLED_APPS'.

Inherit your model from 'ModelWithLog' to make it auto logged:

.. code-block:: python

from django.db import models
from log_models import ModelWithLog

class MyModel(ModelWithLog):
name = models.CharField(max_length=80)
age = models.PositiveSmallIntegerField()

Advanced Usage

.. code-block:: python

from django.db import models
from log_models.models import ModelWithLog
from log_models.models import RegisterLog
from django.contrib.contenttypes.models import ContentType

class Player(ModelWithLog):
name = models.CharField(max_length=80)
age = models.PositiveSmallIntegerField()

def make_log_message(self):
if self.__action_flag__ == 1:
return f"A new Player nome {self.nome} with age {self.age}."
elif self.__action_flag__ == 3:
return f"Player {self.nome} is gone."
return f"The Player change for {self.nome} and age {self.age}."

def get_logs(self):
return RegisterLog.objects.filter(content_type=ContentType(Player),


django-modelwithlog aims to support the same versions of Django currently maintained by the main Django project. See `Django supported versions`_, currently:

* Django 1.10 with Python 3.5
* Django 1.11 (LTS) with Python 3.5 or 3.6

Testing django-modelwithlog Locally

To test against all supported versions of Django:

.. code-block:: shell

$ python test


Twitter: `@moacirbispo`_

Email: ``_

.. _@moacirbispo:


Take a look at the `changelog`_.

.. _changelog:

Project details

Download files

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

Files for django-modelwithlog, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size django-modelwithlog-1.0.1.tar.gz (8.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page