Skip to main content
https://github.com/lambdalisue/django-author/actions/workflows/main.yml/badge.svg https://coveralls.io/repos/github/lambdalisue/django-author/badge.svg?branch=master

Update author and updated_by fields of models automatically

This library is used for updating author and updated_by fields automatically with request.user when the model has created/changed.

Also if you are too lazy to write author = models.ForeignKey(User, _('author'), related_name ...) to every model, just add @with_author decorator to the top of class makes you happy.

Install

This library is on PyPI so you can install it with:

pip install django-author

or from github:

pip install git+https://github.com/lambdalisue/django-author.git

Usage

  1. Add 'author' to your INSTALLED_APPS on settings.py

  2. Add 'author.middlewares.AuthorDefaultBackendMiddleware' to your MIDDLEWARE_CLASSES if you use default author backend

  3. Add author and updated_by field to models which you want to have author and updated_by fields manually or use @with_author decorator like below:

    from django.db import models
    from author.decorators import with_author
    
    @with_author
    class Entry(models.Model):
        title = models.CharField('title', max_length=50)
        body = models.TextField('body')
  4. Done. Now you have automatically updated author and updated_by fields

    If you are in truble, see author_test directory for usage sample.

  5. If you want to forbid modification of the updated_by field for some actions, just set instance._change_updated_by = False before calling save().

Settings

AUTHOR_BACKEND

Class or string path of backend. the backend is used to determine user when object is created/updated.

AUTHOR_CREATED_BY_FIELD_NAME

A name of field. the setting also interfer the name of field created by @with_author decorator. default is ‘author’

AUTHOR_UPDATED_BY_FIELD_NAME

A name of field. the setting also interfer the name of field created by @with_author decorator. default is ‘updated_by’

AUTHOR_DO_NOT_UPDATE_WHILE_USER_IS_NONE

Do not update author or updated_by field when detected user is None. default is True

AUTHOR_MODELS

Check signals for only these models. default is None

AUTHOR_IGNORE_MODELS

Do not check signals for these models. default is [‘auth.user’, ‘auth.group’, ‘auth.permission’, ‘contenttype.contenttype’]

Backend

The default backend use thread_locals storategy to get current request in signal call.

If you want to change the strategy or whatever, create your own backend.

A backend is a class which have get_user method to determine current user.

AuthorDefaultBackend

Default backend. This backend return None when no request found or AnonymousUser create/update object.

AuthorSystemUserBackend

System user backend. This backend return system user when no request found or AnonymousUser create/update object.

system user is determined with get_system_user method and default is User.objects.get(pk=1)

Release files for django-author 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-author 1.2.0
File Size Uploaded
django-author-1.2.0.tar.gz 10.7 kB Details

Release files / django-author-1.2.0.tar.gz

Download URL django-author-1.2.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0c45d986cfe5eb856e968e2c88b552854d3d4e0b69bbca578c6bb5aae06cbd09
BLAKE2b-256 checksum
How to use checksums
a3215f130f2be0de1f462bf58379d9f0c315e76c36c3d5c29fa5aed99fc0b7cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.7

Release history Release notifications | RSS feed

This release

1.2.0 This release

1 release file

1.1.0

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.4.5

1 release file

0.4.4

1 release file

0.4.2

0.4.1

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page