views:

73

answers:

2

Actually, somewhere in the view:

dif = datetime.timedelta(days=1)
today = datetime.date.today()
yesterday = today - dif
ex = Fact.objects.filter(fecha_fact__lte=today ,fecha_fact__gte=yesterday )

It results to this SQL Query:

SELECT `facts_fact`.`id` ...
FROM `facts_fact` 
WHERE (`facts_fact`.`fecha_fact` >= 2009-09-21 AND `facts_fact`.`fecha_fact` <= 2009-09-22 )

There is a way to make Django do a WHERE BETWEEN sentence instead >= <= ?

:) thx.

+4  A: 

Have you tried range?

Fact.objects.filter(fecha_fact__range=(yesterday, today))
Fragsworth
ahhhh this one :) nice :)
Asinox
"RTFM" for me. jeje. thanks!
panchicore
A: 

i dont know, but maybe (gte / lte ):

q1 = Entry.objects.filter(headline__startswith="What")
q2 = q1.exclude(pub_date__gte=datetime.now())
q3 = q1.filter(pub_date__gte=datetime.now())


q = Entry.objects.filter(headline__startswith="What")
q = q.filter(pub_date__lte=datetime.now())
Asinox