@@ -127,6 +127,7 @@ DRF-sideloading is an extension to provide side-loading functionality of related
127127 Include **SideloadableRelationsMixin** mixin in ViewSet and define **sideloading_serializer_class** as shown in example below.
128128 Everything else stays just like a regular ViewSet.
129129 Since version 2.0.0 there are 3 new methods that allow to overwrite the serializer used based on the request version for example
130+ Since version 2.1.0 an additional method was added that allow to add request dependent filters to sideloaded relations
130131
131132 ```python
132133 from drf_sideloading.mixins import SideloadableRelationsMixin
@@ -144,11 +145,11 @@ DRF-sideloading is an extension to provide side-loading functionality of related
144145 # Add prefetches for the viewset as normal
145146 return super().get_queryset().prefetch_related("created_by")
146147
147- def get_sideloading_serializer_class(self):
148+ def get_sideloading_serializer_class(self, request=None ):
148149 # use a different sideloadable serializer for older version
149150 if self.request.version < "1.0.0":
150151 return OldProductSideloadableSerializer
151- return super().get_sideloading_serializer_class()
152+ return super().get_sideloading_serializer_class(request=request )
152153
153154 def get_sideloading_serializer(self, *args, **kwargs):
154155 # if modifications are required to the serializer initialization this method can be used.
@@ -157,6 +158,14 @@ DRF-sideloading is an extension to provide side-loading functionality of related
157158 def get_sideloading_serializer_context(self):
158159 # Extra context provided to the serializer class.
159160 return {"request": self.request, "format": self.format_kwarg, "view": self}
161+
162+ def add_sideloading_prefetch_filter(self, source, queryset, request):
163+ #
164+ if source == "model1__relation1":
165+ return queryset.filter(is_active=True), True
166+ if hasattr(queryset, "readable"):
167+ return queryset.readable(user=request.user), True
168+ return queryset, False
160169 ```
161170
1621716. Enjoy your API with sideloading support
0 commit comments