[Fixed]-How to Query in django ORM for foreign key fields

1👍

From what I understand, you’re just trying to retrieve the employees that belong to a certain company. To do that you can just use either of these.

my_company_instance.employee_set.all()
Employee.objects.filter(dept__name=my_company_instance)

Personally, I prefer the first method.

For more information, you can see Lookups that span relationships

👤Sayse

Leave a comment