how do you order django objects by the attributes of their foreign keys?

You can use something like this:

Model1.objects.all().order_by('-model2__created')

In this code model2 is the related_query_name of model1_foreign_key, which is the class name by default.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top