django Queryset with year(date)='2010' [英] django Queryset with year(date) = '2010'
本文介绍了django Queryset with year(date)='2010'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试建立此查询
select * from m_orders where year(order_date) = '2010'
order_date字段是DateTime字段。我只是不想在这里使用原始sql查询。是否有可能使用例如Django quersets中的MySQL函数?
the field order_date is a DateTime field. I just don't want to use raw sql queries here. Is it even possible to use e.g. MySQL functions in django quersets?
推荐答案
您可以在不使用原始SQL的情况下实现此功能。请使用内置的 __
机制(请参见文档以获取更多详细信息)。像这样的东西:
You can achieve this without using raw SQL. Use the built in __
mechanism instead (see the documentation for more details). Something like this:
MyOrder.objects.filter(order_date__year = 2010)
这篇关于django Queryset with year(date)='2010'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文