I have the following Model and ModelAdmin classes. However when I view the posts in the admin list page, the created
fields are rendered as 2010-03-01 22:15:18.494594
. I've tried setting the DATETIME_FORMAT
variable in settings.py, but that didn't help. Any ideas how to control the formatting of datetime fields in the admin forms.
PS. I know I could write a method in the Post model, that does calls strftime
on the created
field, and render that method instead of created
, but I'm sure there is a better way to handle this.
#models.py
class Post(models.Model):
title = models.CharField(max_length=255)
price = models.DecimalField(max_digits=11, decimal_places=2)
description = models.TextField(blank=True)
category = models.ForeignKey("Category")
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
#admin.py
class PostAdmin(admin.ModelAdmin):
list_display = ("title", "category", "price", "created",)
list_filter = ("category",)
search_fields = ("title", "category__name",)
admin.site.register(Post, PostAdmin)