I want to sort a QuerySet of contacts by a related field. But I do not know how. I tried it like this, but it does not work.
foundContacts.order_by(\"classif
It should be:
foundContacts.order_by("classification__kam")
Here is a link for the Django docs on making queries that span relationships: http://docs.djangoproject.com/en/1.1/topics/db/queries/#lookups-that-span-relationships
You can also see some examples in the order_by
reference:
https://docs.djangoproject.com/en/1.6/ref/models/querysets/#django.db.models.query.QuerySet.order_by
as the documentation indicates, it should be used as in queries about related models
https://docs.djangoproject.com/en/3.0/ref/models/querysets/#order-by
foundContacts.order_by("classification__kam")