DateTimeField(auto_now_add=True) and admin page

660 views
Skip to first unread message

DC

unread,
Dec 9, 2011, 7:46:12 PM12/9/11
to Django users
Hi,

I have the following lines in my model:
entry_date = models.DateTimeField(auto_now_add=True)
pub_date = models.DateTimeField('date published', blank=True,
null=True)
last_change_date = models.DateTimeField(auto_now=True)

Basically, I want the entry date to be added automatically, and last
change date to be updated on every save(), just as described in
documentation. The problem is that those fields don't appear on the
admin page. I tried with explicitly setting those fields in my admin
class, per Tutorial:

class EcoPointAdmin(admin.ModelAdmin):
fieldsets = [
('Details', {'fields': ['title', 'description', 'type',
'status']}),
('Geo data', {'fields': ['latitude', 'longitude']}),
('Dates', {'fields': ['entry_date', 'pub_date',
'last_change_date']}),
]

But now I get the error shown below.

Any chance to have those fields on admin page, without creating my
custom admin? I couldn't find anything useful in the archives.

Thanks,
DC, Django novice

The error msg:

ImproperlyConfigured at /admin/ecopoint/ecopoint/3/

'EcoPointAdmin.fieldsets[2][1]['fields']' refers to field 'entry_date'
that is missing from the form.

Amit

unread,
Dec 10, 2011, 8:23:09 AM12/10/11
to Django users
Hi,

You can display entry_date on admin by using readonly attribute of
admin.
Set readonly = (entry_date,) this will do your task, but You cannot
modify this on admin.


Thanks
Amit

DC

unread,
Dec 10, 2011, 5:53:55 PM12/10/11
to Django users
Hello Amit,

Yes, this is solution - I wanted those fields to be shown in admin, I
understand they're read-only. So, I put this in EcoPointAdmin and it
works:

readonly_fields = ['entry_date', 'last_change_date']

Thank you.

arthur_mwai

unread,
Dec 22, 2012, 5:35:56 PM12/22/12
to django...@googlegroups.com
Readonly doesn't offer flexibility at all sadly. @ DC,i have been experiencing the same problem,but funny thing is other projects prior to this one displayed DateTimeField() on the admin just fine.
Reply all
Reply to author
Forward
0 new messages