Skip to content

Commit

Permalink
Merge pull request #71 from AltSchool/feature/add-hooks-needed-for-fi…
Browse files Browse the repository at this point in the history
…ltering-sideloads

Add serializer hook for filtering sideloads
  • Loading branch information
alexmadjar committed Jan 29, 2016
2 parents 2201270 + 7380df1 commit f824fd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
DESCRIPTION = "Adds Dynamic API support to Django REST Framework."
REPO_NAME = "dynamic-rest"
ORG_NAME = "AltSchool"
VERSION = "1.3.9"
VERSION = "1.3.10"
9 changes: 9 additions & 0 deletions dynamic_rest/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,15 @@ def _filter_queryset(
if query:
queryset = queryset.filter(query)

# A serializer can have this optional function
# to dynamically apply additional filters on
# any queries that will use that serializer
# You could use this to have (for example) different
# serializers for different subsets of a model or to
# implement permissions which work even in sideloads
if hasattr(serializer, 'filter_queryset'):
queryset = serializer.filter_queryset(queryset)

prefetch = prefetches.values()
return queryset.prefetch_related(*prefetch).distinct()

Expand Down

0 comments on commit f824fd5

Please sign in to comment.