DateTimeField doesn't show in admin system DateTimeField doesn't show in admin system django django

DateTimeField doesn't show in admin system


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.


I believe to reason lies with the auto_now_add field.

From this answer:

Any field with the auto_now attribute set will also inherit editable=False and therefore will not show up in the admin panel.

Also mentioned in the docs:

As currently implemented, setting auto_now or auto_now_add to True will cause the field to have editable=False and blank=True set.

This does make sense, since there is no reason to have the field editable if it's going to be overwritten with the current datetime when the object is saved.


Major Hack:

If you really need to do this (as I do) you can always hack around it by immediatley setting the field to be "editable" defining the field as follows:

class Point(models.Model):  mystamp=models.DateTimeField("When Created",auto_now_add=True)  mystamp.editable=True

This will make the field editable, so you can actually alter it. It seems to work fine, at least with the mysql backing engine. I cannot say for certian if other backing stores would make this data immutable in the database and thus cause a problem when editing is attempted, so use with caution.