tags:

views:

23

answers:

3

I have a Django model TimeThingie with two TimeFields called t1 and t2.

How do I get all TimeThingie objects where t1 < t2?

A: 

Use QuerySet.extra() to add custom fields and conditions to the query.

Ignacio Vazquez-Abrams
+1  A: 

You can use F() fields to reference other fields on the model. See http://docs.djangoproject.com/en/dev/topics/db/queries/#filters-can-reference-fields-on-the-model for how to do it.

knutin
+3  A: 

F-objects might be what you want.

TimeThingie.objects.filter(t1__lt=F('t2'))
drmegahertz