MCPcopy Index your code
hub / github.com/encode/django-rest-framework / get_object

Method get_object

rest_framework/generics.py:79–105  ·  view source on GitHub ↗

Returns the object the view is displaying. You may want to override this if you need to provide non-standard queryset lookups. Eg if objects are referenced using multiple keyword arguments in the url conf.

(self)

Source from the content-addressed store, hash-verified

77 return queryset
78
79 def get_object(self):
80 """
81 Returns the object the view is displaying.
82
83 You may want to override this if you need to provide non-standard
84 queryset lookups. Eg if objects are referenced using multiple
85 keyword arguments in the url conf.
86 """
87 queryset = self.filter_queryset(self.get_queryset())
88
89 # Perform the lookup filtering.
90 lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
91
92 assert lookup_url_kwarg in self.kwargs, (
93 'Expected view %s to be called with a URL keyword argument '
94 'named "%s". Fix your URL conf, or set the `.lookup_field` '
95 'attribute on the view correctly.' %
96 (self.__class__.__name__, lookup_url_kwarg)
97 )
98
99 filter_kwargs = {self.lookup_field: self.kwargs[lookup_url_kwarg]}
100 obj = get_object_or_404(queryset, **filter_kwargs)
101
102 # May raise a permission denied
103 self.check_object_permissions(self.request, obj)
104
105 return obj
106
107 def get_serializer(self, *args, **kwargs):
108 """

Callers 4

determine_actionsMethod · 0.45
retrieveMethod · 0.45
updateMethod · 0.45
destroyMethod · 0.45

Calls 4

filter_querysetMethod · 0.95
get_querysetMethod · 0.95
get_object_or_404Function · 0.85

Tested by

no test coverage detected