Question
Asked By – dotty
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?
Now we will see solution for issue: DateTimeField doesn’t show in admin system
Answer
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.
This question is answered By – Shawn Chin
This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0