DateTimeField doesn't show in admin system

dotty picture dotty · Jun 17, 2011 · Viewed 30.8k times · Source

How come my "date" field doesn't come up in the admin system?

In my admin.py file i have

from django.contrib import admin
from glasses.players.models import *
admin.site.register(Rating)

and the Rating model has a field called "date" which looks like this

date = models.DateTimeField(editable=True, auto_now_add=True)

However within the admin system, the field doesn't show, even though editable is set to True.

Does anyone have any idea?

Answer

Hunger picture Hunger · May 14, 2014

If you really want to see date in the admin panel, you can add readonly_fields in admin.py:

class RatingAdmin(admin.ModelAdmin):
    readonly_fields = ('date',)

admin.site.register(Rating,RatingAdmin)

Any field you specify will be added last after the editable fields. To control the order you can use the fields options.

Additional information is available from the Django docs.