Skip to main content

Add special User ForeignKey fields which update automatically

Project description

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.


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

pip install django-author

or from github:

pip install git+


  1. Add 'author' to your INSTALLED_APPS on

  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
    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().



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


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


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


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


Check signals for only these models. default is None


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


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.


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


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)

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-author-1.2.0.tar.gz (10.7 kB view hashes)

Uploaded Source

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