Django自定义查询器过滤器 [英] Django Custom Queryset filters
本文介绍了Django自定义查询器过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如我可以写
MyClass.objects.all()。filter(field = val)
我想做这样的事情:
MyClass.objects.all()。过滤器(customFilter)
我可以使用生成器表达式
(x for MyClass.objects.all()如果customFilter(x))
,但这将失去QuerySets提供的可链接性和其他功能。
解决方案
认为您可能需要自定义管理员。
Is there, in Django, a standard way to write complex, custom filters for QuerySets?
Just as I can write
MyClass.objects.all().filter(field=val)
I'd like to do something like this :
MyClass.objects.all().filter(customFilter)
I could use a generator expression
(x for x in MyClass.objects.all() if customFilter(x))
but that would lose the chainability and whatever other functions the QuerySets provide.
解决方案
I think you may need custom managers.
这篇关于Django自定义查询器过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文