I want to search across two models for objects that have matching names and display a list of them. I can’t figure out if there’s a way to do this with the ORM.
As a very simplified example, say I have these models:
class Company(models.Model):
name = models.CharField(max_length=255, blank=False)
class Person(models.Model):
name = models.CharField(max_length=255, blank=False)
I could write SQL to get a list of matching rows something like this:
SELECT
appname_company.id,
appname_company.name,
appname_person.id,
appname_person.name,
FROM person
LEFT JOIN company ON appname_company.name = appname_person.name;
But in a Django view, if I want to render a table of these matching Companies and Persons, one pair per line, I’m not sure if there’s a good way to do that using the ORM?