I add some lines to your programs as follows to find the point of problem :
First program:
import datetime as dt
import peewee as pw
db = pw.SqliteDatabase('people.db')
class Person(pw.Model):
name = pw.CharField()
birthday = pw.DateField()
class Meta:
database = db # This model uses the "people.db" database.
db.create_tables([Person])
uncle_bob = Person(name='Bob', birthday=dt.date(1960, 1, 21))
uncle_bob.save()
print "----------- Printing object details -----------"
print "Person.birthday ---> ", Person.birthday, " ::::: ",type(Person.birthday)
print "dt.date(1980, 1, 1)---> ", dt.date(1980, 1, 1), " ::::: ",type(dt.date(1980, 1, 1))
print
print "----------- Printing comparison results -----------"
if Person.birthday > dt.date(1980, 1, 1):
print "Person.birthday > dt.date(1980, 1, 1) ?", 'Yes!'
else:
print "Person.birthday > dt.date(1980, 1, 1) ?", 'No!'
print
print "----------- Printing final output without using 'where()' method -----------"
for item in Person.select():
print item.birthday, item.birthday > dt.date(1980, 1, 1)
print
print "----------- Printing final output using 'where()' method -----------"
for item in Person.select().where(Person.birthday > dt.date(1980, 1, 1)):
print item.birthday, item.birthday > dt.date(1980, 1, 1)
print
print "+++++++++++++++++"
print Person.birthday > dt.date(1980, 1, 1)
Its output:
>>> ================================ RESTART ================================
>>>
----------- Printing object details -----------
Person.birthday ---> <peewee.DateField object at 0x033B8970> ::::: <class 'peewee.DateField'>
dt.date(1980, 1, 1)---> 1980-01-01 ::::: <type 'datetime.date'>
----------- Printing comparison results -----------
Person.birthday > dt.date(1980, 1, 1) ? Yes!
----------- Printing final output without using 'where()' method -----------
1960-01-21 False
----------- Printing final output using 'where()' method -----------
+++++++++++++++++
<peewee.Expression object at 0x033BCF90>
>>>
Second program:
import datetime as dt
import peewee as pw
db = pw.SqliteDatabase('people1.db')
class Person(pw.Model):
name = pw.CharField()
birthday = pw.DateField(formats=['%d-%b-%Y'])
class Meta:
database = db # This model uses the "people.db" database.
db.create_tables([Person])
uncle_bob = Person(name='Bob', birthday='21-Jan-1960')
uncle_bob.save()
print "----------- Printing object details -----------"
print "Person.birthday ---> ", Person.birthday, " ::::: ",type(Person.birthday)
print "dt.date(1980, 1, 1)---> ", dt.date(1980, 1, 1), " ::::: ",type(dt.date(1980, 1, 1))
print
print "----------- Printing comparison results -----------"
if Person.birthday > dt.date(1980, 1, 1):
print "Person.birthday > dt.date(1980, 1, 1) ?", 'Yes!'
else:
print "Person.birthday > dt.date(1980, 1, 1) ?", 'No!'
print
print "----------- Printing final output without using 'where()' method -----------"
for item in Person.select():
print item.birthday, item.birthday > dt.date(1980, 1, 1)
print
print "----------- Printing final output using 'where()' method -----------"
for item in Person.select().where(Person.birthday > dt.date(1980, 1, 1)):
print item.birthday, item.birthday > dt.date(1980, 1, 1)
print
print "+++++++++++++++++"
print Person.birthday > dt.date(1980, 1, 1)
Its output:
>>> ================================ RESTART ================================
>>>
----------- Printing object details -----------
Person.birthday ---> <peewee.DateField object at 0x032949D0> ::::: <class 'peewee.DateField'>
dt.date(1980, 1, 1)---> 1980-01-01 ::::: <type 'datetime.date'>
----------- Printing comparison results -----------
Person.birthday > dt.date(1980, 1, 1) ? Yes!
----------- Printing final output without using 'where()' method -----------
1960-01-21 False
----------- Printing final output using 'where()' method -----------
1960-01-21 False
+++++++++++++++++
<peewee.Expression object at 0x03298FF0>
>>>
Well, it seems that there is something wrong with the where()
method!