Skip to content

Fix OrderingFilter labels for annotations with __all__ as ordering_fields - #10073

Merged
auvipy merged 3 commits into
encode:mainfrom
mohamed-alired:fix-ordering-annotation-label
Dec 3, 2026
Merged

auvipy merged 3 commits into
encode:mainfrom
mohamed-alired:fix-ordering-annotation-label

Conversation

@mohamed-alired

Copy link
Copy Markdown
Contributor

Description

With ordering_fields = '__all__', OrderingFilter.get_valid_fields() builds the label of an annotated field with key.title().split('__'), which is a list. The browsable API's ordering menu then shows its repr:

queryset = OrderingFilterModel.objects.annotate(Count('related'))
# menu entry: "['Related', 'Count'] - ascending"

This change joins the parts into a string ("Related Count - ascending"), like the labels of model fields next to it.

Tests: test_get_template_context_annotation_label checks the rendered label. It fails on main and passes with this change.

mohamed-alired and others added 2 commits October 8, 2026 13:30
The label for an annotated field was built with key.title().split('__'),
a list, so the browsable API's ordering menu showed e.g.
"['Related', 'Count'] - ascending". Join the parts into a string
("Related Count - ascending"), like the labels of model fields.

@auvipy auvipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please point to the issue you are trying to fix with this PR?

browniebroke added a commit to browniebroke/drf-playground that referenced this pull request Dec 3, 2026
GenreOrderingAllView uses ordering_fields = "__all__" with an annotation
under Django's default alias (books__count). On affected DRF versions the
browsable API's ordering menu shows the label as a list,
"['Books', 'Count'] - ascending".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@browniebroke

Copy link
Copy Markdown
Collaborator

can you please point to the issue you are trying to fix with this PR?

There is no issue for it yet, but here is how it looks in the browsable API (see here):

image

With this branch, it looks like this:

image

@browniebroke browniebroke changed the title Fix OrderingFilter labels for annotations with ordering_fields='__all__' Fix OrderingFilter labels for annotations with __all__ as ordering_fields Dec 3, 2026
@auvipy
auvipy merged commit a3e6154 into encode:main Dec 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants