aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework
diff options
context:
space:
mode:
Diffstat (limited to 'rest_framework')
-rw-r--r--rest_framework/generics.py5
-rw-r--r--rest_framework/mixins.py3
2 files changed, 6 insertions, 2 deletions
diff --git a/rest_framework/generics.py b/rest_framework/generics.py
index 4015ab20..6d204cf5 100644
--- a/rest_framework/generics.py
+++ b/rest_framework/generics.py
@@ -54,6 +54,7 @@ class GenericAPIView(views.APIView):
# If you want to use object lookups other than pk, set this attribute.
# For more complex lookup requirements override `get_object()`.
lookup_field = 'pk'
+ lookup_url_kwarg = None
# Pagination settings
paginate_by = api_settings.PAGINATE_BY
@@ -278,9 +279,11 @@ class GenericAPIView(views.APIView):
pass # Deprecation warning
# Perform the lookup filtering.
+ # Note that `pk` and `slug` are deprecated styles of lookup filtering.
+ lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
+ lookup = self.kwargs.get(lookup_url_kwarg, None)
pk = self.kwargs.get(self.pk_url_kwarg, None)
slug = self.kwargs.get(self.slug_url_kwarg, None)
- lookup = self.kwargs.get(self.lookup_field, None)
if lookup is not None:
filter_kwargs = {self.lookup_field: lookup}
diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py
index 426865ff..4606c78b 100644
--- a/rest_framework/mixins.py
+++ b/rest_framework/mixins.py
@@ -158,7 +158,8 @@ class UpdateModelMixin(object):
Set any attributes on the object that are implicit in the request.
"""
# pk and/or slug attributes are implicit in the URL.
- lookup = self.kwargs.get(self.lookup_field, None)
+ lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
+ lookup = self.kwargs.get(lookup_url_kwarg, None)
pk = self.kwargs.get(self.pk_url_kwarg, None)
slug = self.kwargs.get(self.slug_url_kwarg, None)
slug_field = slug and self.slug_field or None