Reputation: 46
DateTimeField(auto_now_add=True, null=True)
in my django model.py file and everything is working fine but the problem is it won't show data/time in django admin panel.
Upvotes: 1
Views: 1759
Reputation: 11
Your date modified field may not display when editing an object since it is a read only value. In admin.py, try setting readonly_fields = ("date_modified",)
, replacing date_modified with whatever you named your DateTimeField
Upvotes: 0
Reputation: 4254
you need to add that field to list_display
:
in admin.py
:
class PostAdmin(admin.ModelAdmin): # "PostAdmin" is used for e.g purposes
[..]
list_display = (.., 'created_at',)
[..]
Upvotes: 2
Reputation: 298
when you set:
DateTimeField(auto_now_add=True, null=True)
it will add your object that moment that you post the object, so if you want to select manually, you have to set:
DateTimeField(auto_now_add=False, null=True)
then it will show your Date field in your admin panel model.
Upvotes: 1