db.bookings.start_date.default = ('%s-%s-%s') % (start_day, start_month, start_year)

28 views
Skip to first unread message

Stefan van den Eertwegh

unread,
May 6, 2014, 5:22:46 AM5/6/14
to web...@googlegroups.com
Hi all,

I have the following code:

db.bookings.start_date.default = "%s-%s-%s" % (start_day, start_month, start_year)

The problem is that when i uncomment this line above, i get the following error:

'str' object has no attribute 'year'


This is de database model:
Field('start_date', 'date', default=request.now, requires=[IS_DATE(format=('%d-%m-%Y')), IS_NOT_EMPTY()]),
Field('end_date', 'date', default=request.now, requires=[IS_DATE(format=('%d-%m-%Y')), IS_NOT_EMPTY()]),


I still not get what it could be.

I hope to hear from any of you soon!

Best regards,
Stefan van den Eertwegh

Kyle Flanagan

unread,
May 6, 2014, 9:46:04 AM5/6/14
to web...@googlegroups.com
Try the following:

import datetime
db
.bookings.start_date.default = datetime.date(start_year, start_month, start_day)


Since start_date is the 'date' datatype, it's expecting a python datetime object.

Stefan van den Eertwegh

unread,
May 6, 2014, 11:54:08 AM5/6/14
to web...@googlegroups.com
I have rewrited the code to a hidden input with the default value start_date.
Thanks for you're response!

Op dinsdag 6 mei 2014 15:46:04 UTC+2 schreef Kyle Flanagan:
Reply all
Reply to author
Forward
0 new messages