mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Adds search capability to "owner" API
- Currently a bit of a hack, but it works...
This commit is contained in:
parent
2c889fbcff
commit
3d553cf7de
@ -26,6 +26,37 @@ class OwnerList(generics.ListAPIView):
|
|||||||
queryset = Owner.objects.all()
|
queryset = Owner.objects.all()
|
||||||
serializer_class = OwnerSerializer
|
serializer_class = OwnerSerializer
|
||||||
|
|
||||||
|
def filter_queryset(self, queryset):
|
||||||
|
"""
|
||||||
|
Implement text search for the "owner" model.
|
||||||
|
|
||||||
|
Note that an "owner" can be either a group, or a user,
|
||||||
|
so we cannot do a direct text search.
|
||||||
|
|
||||||
|
A "hack" here is to post-process the queryset and simply
|
||||||
|
remove any values which do not match.
|
||||||
|
|
||||||
|
It is not necessarily "efficient" to do it this way,
|
||||||
|
but until we determine a better way, this is what we have...
|
||||||
|
"""
|
||||||
|
|
||||||
|
search_term = str(self.request.query_params.get('search', '')).lower()
|
||||||
|
|
||||||
|
queryset = super().filter_queryset(queryset)
|
||||||
|
|
||||||
|
if not search_term:
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
results = []
|
||||||
|
|
||||||
|
# Extract search term f
|
||||||
|
|
||||||
|
for result in queryset.all():
|
||||||
|
if search_term in result.name().lower():
|
||||||
|
results.append(result)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
class OwnerDetail(generics.RetrieveAPIView):
|
class OwnerDetail(generics.RetrieveAPIView):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user