Skip to main content

Save model history

Project description


Register fields updates.

WARNING This project currently relies on Django signals (by default post_save, pre_delete, and m2m_changed), so if you do some bulk action (ie via queryset.update()), any action will not be recorded!


Install package with

pip install django-model-history-log


Add model_history.apps.ModelHistoryConfig into your INSTALLED_APPS


and then run

./ migrate

Register a model at startup

You can register a model for logging at startup using History.register helper:

class MyAppConfig(AppConfig):
    name = "myapp"

    def ready(self):
        from model_history.models import History
        from django.contrib.auth import get_user_model

        History.register(get_user_model(), exclude=["password"])

You can register all models with a snippet like this

class MyAppConfig(AppConfig):
    default_auto_field = "django.db.models.BigAutoField"
    name = "myapp"
    verbose_name = _("My Website")

    def ready(self):
        from django.contrib.admin.models import LogEntry
        from django.contrib.auth import get_user_model
        from django.contrib.sessions.models import Session
        from model_history.models import History, HistoryLog

        User = get_user_model()
        History.register(User, exclude=["password"])
        for model in apps.get_models():
            if model not in [LogEntry, History, HistoryLog, Session, User]:


Log a single instance

You can log a single instance changes with the HistoryManager.log() method:

instance = MyInstance.objects.get(...)
  • instance: models.Model = instance to log
  • exclude: list[str] | None = exclude these fields from logging
  • serializer_class: rest_framework.serializers.Serializer | None = use this serializer instance

Query a log

    from django.contrib.auth import get_user_model

    history = History.objects.fetch(User.objects.first())

fetch() always returns an History instance, regardless it is saved on db or not. You must rely on it's pk value or you should check for logs.



  • Docs update


  • Rename project to django-model-history-log (sorry, no migration path)
  • Reformat all codebase with black
  • Update isort/flake8 config
  • Use django JSONField
  • Remove default ordering, use only in admin
  • Add register/unregister actions
  • Add HistoryQuerySet.fetch api
  • Save str(source) as {History,HistoryLog}.label
  • Add en translations
  • Add it translations


  • added missing on_delete on HistoryRow.history field


  • initial relase

Project details

Download files

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

Source Distribution

django-model-history-log-0.2.1.tar.gz (9.7 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page