how to filter with list of values

I have the following models:

class Book(models.Model):
    genres = models.ManyToManyField(
        Genre, related_name='book', blank=True)
class Genre(models.Model):
    name = models.CharField(max_length=100, null=True, blank=True)

I want to filter list of books with selected genres.
Fo example i may have query string something like this


and in i have the following view

class BookList(ListView):
    model = Book
    context_object_name = 'list'

    def get_queryset(self):
            query = self.request.GET.getlist('genre')
            if query:
            return manga

but it doesn’t work and i get an empty list no matter what i choose. I tried replacing ‘icontains’ with ‘in’ but in this case I get duplicate results if the book contains more than 1 match
So I need a way to properly filter my model with zero or more matches

Add the distinct clause to your query. That should eliminate the duplicates.

thank you, it solved my problem