[Python] Django filter queryset __in for *every* item in list

Discussão em 'Python' iniciado por Stack, Agosto 24, 2025.

  1. Stack

    Stack Membro Participativo

    Let's say I have the following models

    class Photo(models.Model):
    tags = models.ManyToManyField(Tag)

    class Tag(models.Model):
    name = models.CharField(max_length=50)


    In a view I have a list with active filters called categories. I want to filter Photo objects which have all tags present in categories.

    I tried:

    Photo.objects.filter(tags__name__in=categories)


    But this matches any item in categories, not all items.

    So if categories would be ['holiday', 'summer'] I want Photo's with both a holiday and summer tag.

    Can this be achieved?

    Continue reading...

Compartilhe esta Página