DateField default value

774 views
Skip to first unread message

Rich Shepard

unread,
Aug 22, 2016, 7:04:11 PM8/22/16
to django...@googlegroups.com
Reading the doc for DateField() I tried to set the default as today's
date, but 'default=date.today' is not accepted.

If there is a way to set today's data as the default for a DateField()
please point me to the doc for it.

Thanks,

Rich

Mike Dewhirst

unread,
Aug 22, 2016, 7:47:49 PM8/22/16
to django...@googlegroups.com

Tim Graham

unread,
Aug 22, 2016, 7:51:31 PM8/22/16
to Django users, rshe...@appl-ecosys.com
What do you mean by "not accepted"? Is there some error message? What you wrote should work as far as I know.

from datetime import date

pub_date = models.DateField(default=date.today)

Rich Shepard

unread,
Aug 22, 2016, 8:34:08 PM8/22/16
to Django users
On Mon, 22 Aug 2016, Tim Graham wrote:

> What do you mean by "not accepted"? Is there some error message? What you
> wrote should work as far as I know.

Tim,

Yes, there was an error message that was not saved.

> from datetime import date

That's probably the cause: my missing that import in the tutorial.

Thanks!

Rich
Reply all
Reply to author
Forward
0 new messages