过滤在Django中的prefetch_related [英] Filter on prefetch_related in Django

查看:123
本文介绍了过滤在Django中的prefetch_related的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法过滤预取的对象?我需要获取最新的()预取对象,但是如果您使用最新的,因为查询更改,则prefetch_related不起作用?



但我希望有一个更简单的解决方法...



https://github.com/ionelmc/django-prefetch#example

解决方案

截至Django 1.7,可以过滤预取的对象。请参阅此SO答案 Django文档


Is there a way of filtering prefetched objects? I need to get the latest() of the prefetched objects but prefetch_related doesn't work if you use latest because the query is changed?

The example here does what I need but I was hoping there's a simpler workaround...

https://github.com/ionelmc/django-prefetch#example

解决方案

As of Django 1.7, filtering prefetched objects is possible. See this SO answer, and the Django documentation.

这篇关于过滤在Django中的prefetch_related的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆