How should django be written in such a way as SQL?

that"s the question. I"ve been looking for it on the Internet for a long time, but I can"t find it.
for example, I want to query
SQL:
select a from atable,btable where atable.id=btable.id

an is the field of atable and b is the field of btable. But I don"t know how to write it with the model class of django. Is there a big god to tell me? be deeply grateful.

Feb.28,2021

your sentence SQL is equivalent to:
select a select b from atable join btable on atable.id=btable.id


find out who's foreign key first, and write

if btable's id is the primary key referencing atable.

from django.db.models import F
Btable.objects.annotate(a=F('atable__a')).values('a', 'b')
Menu