'Django how to search for one Model based on multiple foreign keys?

I'm essentially trying to build a filter based on the model's name and multiple foreign keys.

class Foo(models.Model):
    name = models.Charfield()

class Bar(models.Model):
    name = models.ForeignKey(Foo)

Foo can have the same names, but different Bars.

I want to search for the specific Foo based on Bars.

So far I am able to parse user input and create a list ["foo.name", "bar.name", "bar.name"]

How do I filter the product based on that specific Foo? and with trailing Bars?

# pseudocode process
foo = foo.objects.filter(name__contains=list[0] and foo.objects.filter(bar_name__in=[list]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source