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)
| 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 | """ |
no test coverage detected