Preventing KeyError to be raised

When implementing the `MultipleFieldLookupMixin` as it was, a `KeyError` would be raised when either one of the `lookup_fields` was not present.
This commit is contained in:
Alvaro Cavalcanti 2018-09-06 15:27:57 -03:00 committed by GitHub
parent bc573d8096
commit 8a6b1a3f3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -328,7 +328,7 @@ For example, if you need to lookup objects based on multiple fields in the URL c
queryset = self.filter_queryset(queryset) # Apply any filter backends
filter = {}
for field in self.lookup_fields:
if self.kwargs[field]: # Ignore empty fields.
if field in self.kwargs: # Ignore empty fields.
filter[field] = self.kwargs[field]
obj = get_object_or_404(queryset, **filter) # Lookup the object
self.check_object_permissions(self.request, obj)