0

My main models look like this,

class BusStation(models.Model):
    name = models.CharField()
    location = models.CharField()

class Bus(models.Model):
    name = models.CharField()
    routes = models.ManyToManyField(BusStation)

If a user intends to board a bus, they would need to include take_off_station and destination_station within their search query. The problem is, I'm trying to get the list of buses that contain both take_off and destination points within their route.

I tried:

Bus.objects.filter(
    Q(routes__name__icontains=take_off_station) & 
    Q(routes__name__icontains=destination_station))

this doesn't return anything. When I replaced & for | it returns a queryset that contains at least one of the results i needed. So Please, How do I return all buses that contain both, take_off and Destination within their routes

0 Answers0