Skip to main content

No project description provided

Project description

django_history

Django_history - a module for tracking changes to model instances.

Install

pip3 install git+https://github.com/QuantumaStelata/django-history.git

Add to INSTALLED_APPS

INSTALLED_APPS = [
    ...
    'django_history'
    ...
]

Do migrations

python3 manage.py migrate

Create a model

class Task(models.Model):
  ...

Add mixin to your model

from django_history.mixins import HistoryMixin


class Task(HistoryMixin):
  ...

Note: using a HistoryMixin doesn't need to be migrated

Congrats, history is being recorded

For flexible use, write in the settings.py

# A function that returns the user who made the request.
# NOTE: function must not have arguments.
HISTORY_GET_CURRENT_USER

# If true then the history object will be saved asynchronously using celery_app.
# WARNING: history recording uses pickle serializer.
HISTORY_ALLOW_CELERY

# If you are deleting objects programmatically,
# pass in a list of field names that store information about deleting the object
# to more accurately create a history object.
HISTORY_SOFT_DELETE_FIELDS

For example

  1. Using soft delete model
# models.py
class Task(HistoryMixin):
  ...
  deleted_at = models.DateTimeField(null=True)
  ...

# settings.py
# Pass soft delete field in HISTORY_SOFT_DELETE_FIELDS
HISTORY_SOFT_DELETE_FIELDS = ['deleted_at']
  1. If you use django-currentuser, pass get_current_user function to HISTORY_GET_CURRENT_USER
# settings.py
from django_currentuser.middleware import get_current_user

HISTORY_GET_CURRENT_USER = get_current_user

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_histories-1.0.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

django_histories-1.0.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file django_histories-1.0.2.tar.gz.

File metadata

  • Download URL: django_histories-1.0.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for django_histories-1.0.2.tar.gz
Algorithm Hash digest
SHA256 75d9c5a4310e7efa5d7de114da730ca1c799bebb190a2183ade47f12c6dabca1
MD5 3ff854aa25e873064144109c9a6ac55a
BLAKE2b-256 84f31f7270dfe44b48a0db972b0642317b3cb7fe698cbef0af9e4113f8c3fae0

See more details on using hashes here.

File details

Details for the file django_histories-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_histories-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c70e4b34df95e4cca073e3d9b9ca52a108ddaf8fb8ff50370c66c4849793bcda
MD5 b5148d00f2411735b255194286157923
BLAKE2b-256 aafa6dd2bfc6422051a2b2bed369a9a9a55e4760e871c009dd5d0badfea1ad91

See more details on using hashes here.

Supported by

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