Commit e91ffc87 by Xavier Ordoquy

Ignore empty args in the `MultipleFieldLookupMixin` definition - Closes #4484

parent 6b6f3195
...@@ -330,7 +330,8 @@ For example, if you need to lookup objects based on multiple fields in the URL c ...@@ -330,7 +330,8 @@ 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 queryset = self.filter_queryset(queryset) # Apply any filter backends
filter = {} filter = {}
for field in self.lookup_fields: for field in self.lookup_fields:
filter[field] = self.kwargs[field] if self.kwargs[field]: # Ignore empty fields.
filter[field] = self.kwargs[field]
return get_object_or_404(queryset, **filter) # Lookup the object return get_object_or_404(queryset, **filter) # Lookup the object
You can then simply apply this mixin to a view or viewset anytime you need to apply the custom behavior. You can then simply apply this mixin to a view or viewset anytime you need to apply the custom behavior.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment