Django ORM where in two columns with subquery

Viewed 48

Imagine I have two tables. One lists licenses customers have, each with a specific version and type. The other table has general shared info about the licenses (eg name, price, duration), also listed by type and version.

I need to query the information table for any rows pertaining to licenses a given customer has. In pure SQL, that can be accomplished with this subquery:

select * from version_details where (version, type) in (select version, type from licenses where company_id = '6f65e5cc-cd1f-4888-a236-38295bae393a');

Is there a way to accomplish this with Django ORM? I know how to use a subquery but I can't figure out how to do a wherein with two columns.

1 Answers
license = License.objects.get(company_id='6f65e5cc-cd1f-4888-a236-38295bae393a')
verson = VersionDetails.objects.filter(version=license.version, type=license.type)
Related