Metron-Project / metron

Django website for a comic book database
https://metron.cloud/
GNU General Public License v3.0
90 stars 7 forks source link

Improve Series name filter for REST API queries. #125

Closed bpepple closed 2 years ago

bpepple commented 2 years ago

Is your feature request related to a problem? Currently, when querying the Series or Issue endpoints for the series_name param should split any words instead of using it as a single word. For example, a param of "Batman Superman" should be split into two words and used to filter.

Describe the solution you'd like Should be similar to how the SearchSeriesList() View's queryset is handled:

class SearchSeriesList(SeriesList):
    def get_queryset(self):
        result = super(SearchSeriesList, self).get_queryset()
        if query := self.request.GET.get("q"):
            query_list = query.split()
            result = result.filter(
                reduce(operator.and_, (Q(name__icontains=q) for q in query_list))
            )

        return result