Skip to content

Fix OrderingFilter labels for annotations with ordering_fields='__all__' - #10073

Open
mohamed-alired wants to merge 1 commit into
encode:mainfrom
mohamed-alired:fix-ordering-annotation-label
Open

mohamed-alired wants to merge 1 commit 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.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant