Doubt understanding custom db.table.insert date field format

19 views
Skip to first unread message

Miquel Fontanals

unread,
Oct 5, 2014, 3:56:46 AM10/5/14
to web...@googlegroups.com
Hi all,

I've a simple model like this
db.define_table("lot",
    Field('name', 'string', length=1024, required=True, unique=True),
    Field('start_date, 'date', required=True)
)

db.lot.start_date.requires = IS_DATE(format=T('%Y-%m-%d'),error_message=T('must be YYYY-MM-DD!'))


And I have a custom CSV import that implies multiple tables including this one.

db.lot.insert(
name=line["NAME"],
start_date=line["S_DATE"]
)

(line is a csv row)

However the S_DATE column has format DD/MM/YYYY


I'm working with git trunk and using Postgres and (magically?) all imported dates are correct, I mean, there are no errors and there is no confusion between dd/mm/yyyy and mm/dd/yyyy for dates like 06/04/2012


How this can be possible? It's because of my development machine or postgres locale? (My language file is not in web2py yet so the web interface is in english and so the date format in admin app database administration is yyyy-mm-dd, just to clarify that this is not because of T in format)


Anyway, the question is how can I define/ensure that such dates will be always well inserted when importing the CSV?

Because looks like the requires is_date format is not affecting the db.table.insert, is it?

Thanks in advance,
Miki


Reply all
Reply to author
Forward
0 new messages