Skip to content

OrderingFilter does not accept related fields (relation.field / relation__field) in sort? #1317

@jaimeres

Description

@jaimeres

Hi,

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:

{ "errors": [{ "detail": "invalid sort parameter: responsible_level.level", "status": "400", "code": "invalid" }] }

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?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions