AltSchool / dynamic-rest

Dynamic extensions for Django REST Framework
MIT License
831 stars 109 forks source link

Is there a way to change the disable_prefetches in dynamicfilterbackend on the fly? #299

Open simkimsia opened 4 years ago

simkimsia commented 4 years ago

For a viewset, that uses the dyanamicmodelviewset, under the retrieve action, i need to improve the performance.

So I want to turn off the prefetches under the get_object method.

Is there a way for me to change the disable_prefetches on the fly? Otherwise, i need to avoid filter_queryset in the get_object method for the viewset

Right now I do it like this


def get_object(self, disable_filter_queryset=False):
        """
        Returns the object the view is displaying.
        You may want to override this if you need to provide non-standard
        queryset lookups.  Eg if objects are referenced using multiple
        keyword arguments in the url conf.
        """
        # disable the filter_queryset when retrieve this is because no smple way to turn off prefetches
        # https://github.com/AltSchool/dynamic-rest/issues/299
        if disable_filter_queryset:
            queryset = self.get_queryset()
        else:
            queryset = self.filter_queryset(self.get_queryset())

but is there a better way?