mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Ignore empty args in the MultipleFieldLookupMixin
definition - Closes #4484
This commit is contained in:
parent
6b6f319509
commit
e91ffc87cb
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user