[Answered ]-How can i change this query to ORM? (JOIN without foreign key and order by second table)

1👍

Since you want the data of the Process. It makes more sense to work with:

qs = Process.objects.filter(
    sample__isnull=False
).select_related('sample').order_by('endstat')

This will also fetch the related data for the related Sample, you thus can process this by accessing the fields of the .sample attribute:

for process in qs:
    print(process.sample.name)

Leave a comment