mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 10:03:57 +03:00
Added get_queryset method to ListModelMixin.
This can be easily re-implemented in a view, to allow the user to take such things as request.user into account when creating the queryset.
This commit is contained in:
parent
0a5ca000ed
commit
338e77837c
|
@ -675,9 +675,7 @@ class ListModelMixin(ModelMixin):
|
||||||
queryset = None
|
queryset = None
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
model = self.resource.model
|
queryset = self.get_queryset()
|
||||||
|
|
||||||
queryset = self.queryset if self.queryset is not None else model.objects.all()
|
|
||||||
|
|
||||||
if hasattr(self, 'resource'):
|
if hasattr(self, 'resource'):
|
||||||
ordering = getattr(self.resource, 'ordering', None)
|
ordering = getattr(self.resource, 'ordering', None)
|
||||||
|
@ -689,6 +687,10 @@ class ListModelMixin(ModelMixin):
|
||||||
queryset = queryset.order_by(*args)
|
queryset = queryset.order_by(*args)
|
||||||
return queryset.filter(self.build_query(**kwargs))
|
return queryset.filter(self.build_query(**kwargs))
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
model = self.resource.model
|
||||||
|
return model.objects.all() if self.queryset is None else self.queryset
|
||||||
|
|
||||||
|
|
||||||
########## Pagination Mixins ##########
|
########## Pagination Mixins ##########
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user