djangosnippets.org: Latest snippets tagged with 'timestamp'https://djangosnippets.org/tags/timestamp/2008-09-03T20:31:19.327839-05:00Timestamps in Model
2008-09-03T20:31:19.327839-05:00lindsayrgwatthttps://djangosnippets.org/snippets/1017/<p>A simple way to add <code>date_created</code> and <code>date_modified</code> timestamps to a model. Adds a <code>date_created</code> timestamp when the object is first created and adds a <code>date_modified</code> timestamp whenever the item is saved.</p>
<p><strong>Note:</strong> You might be tempted instead to use: <code>date_created=models.DateTimeField(default=datetime.now())</code> but that won't work as Python will calculate <code>datetime.now() …</code></p>
Freely redistributable