Combing two querries using Q objects in Django?

I have defined following view:

class SearchListView(ListView):
    template_name = "movies/search_list.html"

    # overwriting the get_queryset function to customize the queryset
    def get_queryset(self) -> list:
        query = self.request.GET.get("q")
        if query:
            movies = list(
                filter(
                    lambda x: unidecode(query.lower()) in unidecode(x.title).lower(),
                    Movie.objects.all(),
                )
            )
            actors = list(
                filter(
                    lambda x: unidecode(query.lower()) in unidecode(x.name).lower(),
                    Actor.objects.all(),
                )
            )
            # use the chain function to combine the querysets
            return list(chain(movies, actors))
        else:
            # return an empty list if no query is provided
            return []

And it is working as I want it to, however I have been trying to combine the querries into one querry using Q objects, but did not succeed. Do you think it's even possible in this case?

Back to Top