Ignore empty args in the MultipleFieldLookupMixin definition - Closes #4484

This commit is contained in:
Xavier Ordoquy 2016-09-13 07:21:10 +02:00
parent 6b6f319509
commit e91ffc87cb

View File

@ -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
filter = {}
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
You can then simply apply this mixin to a view or viewset anytime you need to apply the custom behavior.