mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-29 01:20:02 +03:00
add checks before make filter kwargs
This commit is contained in:
parent
d74a5bfd18
commit
c25971c754
|
@ -84,6 +84,9 @@ class GenericAPIView(views.APIView):
|
||||||
keyword arguments in the url conf.
|
keyword arguments in the url conf.
|
||||||
"""
|
"""
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
queryset = self.filter_queryset(self.get_queryset())
|
||||||
|
lookup_arg = self.lookup_arg
|
||||||
|
|
||||||
|
if lookup_arg is None:
|
||||||
|
|
||||||
# Perform the lookup filtering.
|
# Perform the lookup filtering.
|
||||||
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
|
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
|
||||||
|
@ -94,8 +97,9 @@ class GenericAPIView(views.APIView):
|
||||||
'attribute on the view correctly.' %
|
'attribute on the view correctly.' %
|
||||||
(self.__class__.__name__, lookup_url_kwarg)
|
(self.__class__.__name__, lookup_url_kwarg)
|
||||||
)
|
)
|
||||||
|
filter_kwargs = {self.lookup_field: self.kwargs[lookup_url_kwarg]}
|
||||||
|
|
||||||
lookup_arg = self.lookup_arg
|
else:
|
||||||
|
|
||||||
assert lookup_arg in self.request.GET, (
|
assert lookup_arg in self.request.GET, (
|
||||||
'Expected view %s to be called with a URL keyword argument '
|
'Expected view %s to be called with a URL keyword argument '
|
||||||
|
@ -104,9 +108,7 @@ class GenericAPIView(views.APIView):
|
||||||
(self.__class__.__name__, lookup_arg)
|
(self.__class__.__name__, lookup_arg)
|
||||||
)
|
)
|
||||||
|
|
||||||
filter_kwargs = {self.lookup_field: self.request.GET[lookup_arg]} \
|
filter_kwargs = {self.lookup_field: self.request.GET[lookup_arg]}
|
||||||
if lookup_arg is not None \
|
|
||||||
else {self.lookup_field: self.kwargs[lookup_url_kwarg]}
|
|
||||||
|
|
||||||
obj = get_object_or_404(queryset, **filter_kwargs)
|
obj = get_object_or_404(queryset, **filter_kwargs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user