All the examples directly set queryset for views. The documentation says that I should override the get_queryset() on them, but call super().get_queryset(), but this really does not work if we do not have the base class that would stop propagation of this call to the rest_framework's get_queryset(), which asserts the queryset is set.
https://github.com/encode/django-rest-framework/blob/e454758fb6edf1dcf5aa5417a388b940c871469c/rest_framework/generics.py#L67
I really liked the concept of this project trying to avoid all the mess with splitting queries and models, but only way how I was able to make this working was something like this:
class BaseVirtualModelListApiView(ListAPIView):
def get_queryset(self):
# make sure the ListApiView.get_queryset() is not called
return self.model.objects
class MyVirtualModelListApiView(v.GenericVirtualModelViewMixin, BaseVirtualModelListApiView):
pass
class BlogPostsView(MyVirtualModelListApiView):
model = Blog
Not sure if I am just stupid or there is some better way. In any case, it would be good do document how this should work.
All the examples directly set queryset for views. The documentation says that I should override the
get_queryset()on them, but callsuper().get_queryset(), but this really does not work if we do not have the base class that would stop propagation of this call to therest_framework'sget_queryset(), which asserts thequerysetis set.https://github.com/encode/django-rest-framework/blob/e454758fb6edf1dcf5aa5417a388b940c871469c/rest_framework/generics.py#L67
I really liked the concept of this project trying to avoid all the mess with splitting queries and models, but only way how I was able to make this working was something like this:
Not sure if I am just stupid or there is some better way. In any case, it would be good do document how this should work.