Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions rest_flex_fields/filter_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,19 @@ def filter_queryset(

queryset = queryset.prefetch_related(*(
model_field.name for model_field in nested_model_fields if
(model_field.is_relation and not model_field.many_to_one) or
(model_field.is_relation and model_field.many_to_one and not model_field.concrete) # Include GenericForeignKey)
(
(model_field.is_relation and not model_field.many_to_one) or
(model_field.is_relation and model_field.many_to_one and not model_field.concrete) # Include GenericForeignKey)
) and
(model_field.name not in self._get_prefetches_ignores())
)
)

return queryset

def _get_prefetches_ignores(self):
return []

@staticmethod
@lru_cache()
def _get_field(field_name: str, model: models.Model) -> Optional[models.Field]:
Expand Down