can't compare datetime.date to Field

267 views
Skip to first unread message

lucas

unread,
Jul 16, 2013, 12:16:07 PM7/16/13
to web...@googlegroups.com
can't i limit a query based on a between date thingy like below?

    today = datetime.date.today()
    tCls = db.classes
    rows = db((tCls.starting_date<=today) & (today<=tCls.ending_date)).select()

i also tried 

    today = datetime.datetime.today()

where the fields are defined as:

    Field('starting_date', 'date', comment='When the class first opens, format YYYY-MM-DD', requires=NE, default=datetime.date.today()+datetime.timedelta(weeks=1)),
    Field('ending_date', 'date', comment='The difference between the starting and ending dates will form the span for rolling enrollment, format YYYY-MM-DD', requires=NE, default=datetime.date.today()+datetime.timedelta(weeks=17)),

any ideas?  lucas
but i get the error:

TypeError: can't compare datetime.date to Field

any ideas?  lucas

Massimo Di Pierro

unread,
Jul 16, 2013, 2:05:02 PM7/16/13
to web...@googlegroups.com
rows = db((tCls.starting_date<=today) & (tCls.ending_date>=today)).select()

The syntax is always field<=value, never value>=field.

lucas

unread,
Jul 16, 2013, 10:57:02 PM7/16/13
to web...@googlegroups.com
omg, that is amazing.  strange syntax.  why not interchangeable?  lucas

David Marko

unread,
Jul 17, 2013, 4:16:18 AM7/17/13
to web...@googlegroups.com
I think this is because '>=' are methods on field object ...

Dne středa, 17. července 2013 4:57:02 UTC+2 lucas napsal(a):

Massimo Di Pierro

unread,
Jul 17, 2013, 5:34:11 AM7/17/13
to web...@googlegroups.com
Because the __lt__ operator is overloaded for the field object but not for the value (which can be int, float, etc.) If you have an idea about how to do that, let me know.
Reply all
Reply to author
Forward
0 new messages