Search code examples
djangodjango-1.4

Filter on prefetch_related in 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


Solution

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