Bdfy
Bdfy

Reputation: 24621

How to use where > date in django orm?

How to use where > date in django orm ?

It's work:

 res = Prog.objects.filter(end = datetime.now()).order_by('-start')

but this not work:

 res = Prog.objects.filter(end > datetime.now()).order_by('-start')

Why ?

Upvotes: 0

Views: 122

Answers (1)

Paolo Bergantino
Paolo Bergantino

Reputation: 488394

Read the documentation:

gt

Greater than.

Example:

Entry.objects.filter(id__gt=4)

SQL equivalent:

SELECT ... WHERE id > 4;

In your case it would be:

res = Prog.objects.filter(end__gt=datetime.now()).order_by('-start') 

Upvotes: 6

Related Questions