I used this template in the Django Rest Framework (DRF) 2:
class Foo(models.Model): user = models.ForeignKey(User) class FooSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Foo fields = ('url') class FooViewset(viewsets.ModelViewSet): def get_queryset(self): return Foo.objects.filter(user=self.request.user) serializer = FooSerializer model = Foo # <-- the way a ModelViewSet is told what the object is in DRF 2 [ in urls.py] from rest_framework import routers router = routers.DefaultRouter() router.register('Foo', views.FooViewSet)
In DRF 3, I now get:
AssertionError at / `base_name` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.
How is get_queryset overridden for an instance of rest_framework.viewsets.ModelViewSet ?
django-rest-framework
Ross rogers
source share