Added default get_queryset method to base endpoint

pull/1772/head
Karl Hobley 2015-08-24 14:11:36 +01:00
rodzic 67ff876542
commit 2a2b3a412b
1 zmienionych plików z 3 dodań i 3 usunięć

Wyświetl plik

@ -30,7 +30,6 @@ class BaseAPIEndpoint(GenericViewSet):
base_serializer_class = BaseSerializer
filter_classes = []
model = None # Set on subclass
queryset = None # Set on subclasses or implement `get_queryset()`.
known_query_parameters = frozenset([
'limit',
@ -42,6 +41,9 @@ class BaseAPIEndpoint(GenericViewSet):
extra_api_fields = []
name = None # Set on subclass.
def get_queryset(self):
return self.model.objects.all().order_by('id')
def listing_view(self, request):
queryset = self.get_queryset()
self.check_query_parameters(queryset)
@ -213,7 +215,6 @@ class PagesAPIEndpoint(BaseAPIEndpoint):
class ImagesAPIEndpoint(BaseAPIEndpoint):
queryset = get_image_model().objects.all().order_by('id')
base_serializer_class = ImageSerializer
filter_backends = [FieldsFilter, OrderingFilter, SearchFilter]
extra_api_fields = ['title', 'tags', 'width', 'height']
@ -222,7 +223,6 @@ class ImagesAPIEndpoint(BaseAPIEndpoint):
class DocumentsAPIEndpoint(BaseAPIEndpoint):
queryset = Document.objects.all().order_by('id')
base_serializer_class = DocumentSerializer
filter_backends = [FieldsFilter, OrderingFilter, SearchFilter]
extra_api_fields = ['title', 'tags']