Custom list display of model timestamps for Django Admin.
Project description
Show human readable created/modified dates and times in the django.contrib.admin changelist for models that track the moment of creation and updates.
Usage
First you will need to have a model that tracks the moment of creation and modification. The barebones example for that is:
from django.db import models class TimestampedItem(models.Model): created = models.DateTimeField('created', auto_now_add=True) modified = models.DateTimeField('modified', auto_now=True)
Or, if you are using django-extensions:
from django_extensions.db.models import TimeStampedModel class TimestampedItem(TimeStampedModel): pass
Now it’s time to register this model with Django’s admin site.
Create a admin class, just like you’d usually do, but make it extend TimestampedAdminMixin as well as any other base admin class you use:
from django.contrib import admin from models import TimestampedItem from admintimestamps import TimestampedAdminMixin class TimestampedAdmin(TimestampedAdminMixin, admin.ModelAdmin): pass admin.site.register(TimestampedItem, TimestampedAdmin)
That’s it!
Configuration
If the names of you timestamp fields aren’t created and modified but for example created_at and modified_at you’ll need to do a tiny bit of configuration in the model admin class:
class TimestampedAdmin(TimestampedAdminMixin, admin.ModelAdmin): timestamp_fields = ('created_at', 'modified_at')
Changelog for django-admin-timestamps
1.0.1 (2011-10-11)
Fixed setup.py to include the compat subpackage
1.0.0 (2011-10-07)
Initial release
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
File details
Details for the file django-admin-timestamps-1.0.1.tar.gz
.
File metadata
- Download URL: django-admin-timestamps-1.0.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54e7d94cd2cf379c0430e488f1411cf000251a7f412e7f69c8254c0a40a1c5f2 |
|
MD5 | f7058173f57b902b196e4717b964446a |
|
BLAKE2b-256 | 3a0608b1a5605f2340ed0d47d95b3b8500f52716366b356434eaff908ec538fe |