30 lines
946 B
Python
30 lines
946 B
Python
from apps.core.services.filter.search import DynamicSearchService
|
|
|
|
|
|
class DynamicSearchMixin:
|
|
""" search query sets with introduced fields in view set """
|
|
|
|
def get_search_fields(self):
|
|
return getattr(self, "search_fields", [])
|
|
|
|
def get_date_field(self):
|
|
return getattr(self, "date_field", "create_date")
|
|
|
|
def filter_queryset(self, queryset):
|
|
queryset = super().filter_queryset(queryset) # noqa
|
|
|
|
q = self.request.query_params.get("search") # noqa
|
|
start = self.request.query_params.get("start") # noqa
|
|
end = self.request.query_params.get("end") # noqa
|
|
search_fields = self.get_search_fields()
|
|
date_field = self.get_date_field()
|
|
|
|
return DynamicSearchService(
|
|
queryset=queryset,
|
|
query_string=q,
|
|
search_fields=search_fields,
|
|
start=start,
|
|
end=end,
|
|
date_field=date_field
|
|
).apply()
|