Django: QuerySet with objects where one time is earlier than another
I have a Django model TimeThingie
with two TimeField开发者_如何学JAVA
s called t1
and t2
.
How do I get all TimeThingie
objects where t1 < t2
?
F-objects might be what you want.
TimeThingie.objects.filter(t1__lt=F('t2'))
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.
Use QuerySet.extra()
to add custom fields and conditions to the query.
精彩评论