Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #34566 - ModelAdmin get_field_queryset uses related admin ordering, but not related admin querysets. #16859

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions django/contrib/admin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ def get_field_queryset(self, db, db_field, request):
if related_admin is not None:
ordering = related_admin.get_ordering(request)
if ordering is not None and ordering != ():
return db_field.remote_field.model._default_manager.using(db).order_by(
*ordering
)
return related_admin.get_queryset(request).order_by(*ordering)
Copy link

Choose a reason for hiding this comment

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

This change seems to totally disregard the 'db' parameter. So, it looks like it'll always use the default data source, which might lead to some surprises in projects with multiple databases when users want to query sources other than the default one.

return None

def formfield_for_foreignkey(self, db_field, request, **kwargs):
Expand Down