Repository navigation
Fix OrderingFilter labels for annotations with __all__ as ordering_fields - #10073
Merged
Merged
Conversation
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
reviewed
Nov 28, 2026
auvipy
left a comment
Collaborator
There was a problem hiding this comment.
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>
Collaborator
There is no issue for it yet, but here is how it looks in the browsable API (see here):
With this branch, it looks like this:
|
browniebroke
approved these changes
Dec 3, 2026
OrderingFilter labels for annotations with __all__ as ordering_fields
auvipy
approved these changes
Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
With
ordering_fields = '__all__',OrderingFilter.get_valid_fields()builds the label of an annotated field withkey.title().split('__'), which is a list. The browsable API's ordering menu then shows its repr: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_labelchecks the rendered label. It fails onmainand passes with this change.