1
0
mirror of https://github.com/django/django.git synced 2025-04-04 13:36:42 +00:00

Fixed #34566 : ModelAdmin get_field_queryset uses related admin ordering, but not related admin querysets.

This commit is contained in:
Krishna2864 2023-11-28 02:39:38 +05:30
parent 729266c6f2
commit 27252c911d

View File

@ -259,11 +259,13 @@ class BaseModelAdmin(metaclass=forms.MediaDefiningClass):
except NotRegistered:
return None
else:
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
)
if related_admin is not None:
ordering = related_admin.get_ordering(request)
if ordering is not None and ordering != ():
queryset = related_admin.get_queryset(request)
if db:
queryset = queryset.using(db)
return queryset.order_by(*ordering)
return None
def formfield_for_foreignkey(self, db_field, request, **kwargs):