You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OrderingFilter does not accept related fields (relation.field / relation__field) in sort? #1317
I'm trying to sort a resource by a field from a related model using the ?sort=
Current behavior: When I send ?sort=responsible_level.level, the API returns:
Expected behavior:
Be able to sort by a field on a related model, e.g. ?sort=responsible_level.level mapping to the ORM lookup responsible_level__level.
Questions:
Does OrderingFilter support sorting by relationship fields using dot notation (relationship.field or relationship__field)?
If not, what is the recommended approach to allow sorting by a related model's field while staying compliant with the JSON:API spec?
Is there a way to define aliases in ordering_fields that map to ORM __ lookups for related fields?
Activity
sliverc commentedon Mar 27, 2026
Thanks for your message. In the view you want to sort how did you define
ordering_filelds?This is an internal field so you should define it with a __ but in the API call (query param) you can then use a dot notation.
define all fields you want to allow to be ordered too. Does this work?
sliverc commentedon Oct 8, 2026
As noted in comment
ordering_fieldsneeds to be defined so sorting of a relation field is possible.#1334 added some clarification in the docs about this.