If I understand what you're doing there it is a limitation of the
language. db.entry.DT my_DT works because Field has defined a
special language construct for when the datetime is compared to the
Field. However, my_DT db.entry.DT does not work, because there you
are comparing a Field to a datetime. Python (and C++, etc) allow you
to define a function to be called when your object is on the left side
of a comparison, but not if it is on the right (unless, of course, an
object of that class is on both sides of the operator).
This could be avoided if someone wanted to custom extend the datetime
object to define the comparison functions, but then a person would
have to use contrib.datetime instead of the built in datetime class.
It's just _The Way Things Are_ and is common for languages which allow
a custom override of comparison operators.
--Greg
On Aug 18, 6:43 pm, Luis Goncalves lgoncal...@gmail.com wrote:
Let
my_DT = datetime.datetime( 2011, 08, 16)
db.define_table( 'entry', Field('DT' = 'datetime' ) )
(and add data records to the database ...)
In a db query, this works:
db( db.entry.DT my_DT).select()
but this does not:
db( my_DT db.entry.DT).select()
producing error : can't compare datetime.datetime to Field
Why does that happen?
Thanks,
Luis.