[Answered ]-Django filtering by a value which might be in a many-to-many field

2👍

from django.db.models import Q

# drivers who have either have a "Yugo" as their primary car,
# or have a relation to one
yugo_drivers = Driver.objects.filter(Q(primary_car__name__iexact="Yugo") | 
                                     Q(cars__name__iexact="Yugo"))

Two things that will help you out are:

👤Matt

0👍

qs = Driver.objects.filter(Car_name=your_car.name)

Leave a comment