Django’s auto_now and auto_now_add fields for auditing creation and modification timestamps

Adrienne Domingus
3 min readJan 26, 2020

Adding fields to database schemas to audit the creation and modification is a common best practice, useful for any number of things, most commonly debugging and cache invalidation. The good news is, Django has field-types built for just this purpose!

auto_now and auto_now_add fields

As always, let’s start with the docs!

These fields are built into Django for expressly this purpose — auto_now fields are updated to the current timestamp every time an object is saved and are therefore perfect for tracking when an object was last modified, while an auto_now_add field is saved as the current timestamp when a row is first added to the database, and is therefore perfect for tracking when it was created.

It’s worth noting that that both fields are set on initial creation, whether they go through .save() or bulk_create - they may be a few milliseconds different, but will be effectively the same, but an auto_now_add field won’t change again after it’s set.

Let’s dive in and talk through some quirks of these fields.

Read-only fields

--

--