Skip to content

Incorrect Sorting on Organization/Campus Lists #2662

Description

@aishwaryanair440

Description

The dashboard list APIs support sorting by related fields such as organization (org) or campus. However, when sorting is applied, the API sorts by the UUID of the related object instead of the human-readable name/title.

This results in lists that appear randomly ordered to users, since UUID strings do not correspond to meaningful alphabetical ordering.

This affects usability in dashboards where users expect organizations or campuses to be sorted alphabetically.


Goals

  • Identify where sorting for related fields is implemented in the dashboard APIs
  • Modify sorting logic to use readable fields like organization__title instead of UUID
  • Ensure sorting works consistently for both org and campus
  • Verify alphabetical ordering across all list APIs
  • Add tests to prevent regression

Expected Outcome

When a dashboard list API is called with sorting parameters such as ?sortBy=org, the results should be ordered alphabetically based on the organization's title (for example organization__title). The same behavior should apply for campus sorting using the campus name/title field.

The API should return results in a predictable alphabetical order that is meaningful to users.


Acceptance Criteria

  • Sorting by ?sortBy=org orders results alphabetically by organization title
  • Sorting by ?sortBy=campus orders results alphabetically by campus name
  • Sorting should not use UUID values for ordering
  • API responses remain backward compatible
  • Tests confirm correct sorting behavior

Implementation Details

The issue likely occurs because the query ordering uses the related object's UUID field instead of a readable attribute.

Instead of ordering by the related object ID (e.g., organization_id), the queryset should order by the related object's title field such as:

organization__title
campus__title

The sorting logic inside the queryset or filter backend should be updated accordingly.


Mockups / Wireframes

Not required since this is a backend API issue.


Product Name

mulearn

Project Name

[BUG] Incorrect Sorting on Organization/Campus Lists

Tech Skills Needed

Python, Django, REST APIs, Database Query Optimization

Mentor(s)

@Mentor1 @mentor2

Complexity

Medium

Category

Bug

Sub Category

Backend, API, Reproducible

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions