开发者

Django: QuerySet with objects where one time is earlier than another

开发者 https://www.devze.com 2022-12-27 15:56 出处:网络
I have a Django model TimeThingie with two TimeField开发者_如何学JAVAs called t1 and t2. How do I get all TimeThingie objects where t1 < t2?F-objects might be what you want.

I have a Django model TimeThingie with two TimeField开发者_如何学JAVAs 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号