mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #26565 -- Errored nicely when using Prefetch with a values() queryset.
Thanks Maxime Lorant for the report and Anssi for the suggestion.
This commit is contained in:
@@ -1331,6 +1331,8 @@ class Prefetch(object):
|
||||
self.prefetch_through = lookup
|
||||
# `prefetch_to` is the path to the attribute that stores the result.
|
||||
self.prefetch_to = lookup
|
||||
if queryset is not None and queryset._iterable_class is not ModelIterable:
|
||||
raise ValueError('Prefetch querysets cannot use values().')
|
||||
if to_attr:
|
||||
self.prefetch_to = LOOKUP_SEP.join(lookup.split(LOOKUP_SEP)[:-1] + [to_attr])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user