summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2018-10-19 15:41:29 +0200
committerTim Graham <timograham@gmail.com>2018-11-14 14:29:39 -0500
commit6d4e5feb79f7eabe8a0c7c4b87f25b1a7f87ca0b (patch)
tree23294d3f78038e93ad1494ce9957b6e7f29ca2ce /django/db
parent35a08b8541c856a51b2ab718e0a2fe060debfa2a (diff)
Fixed #29835 -- Made RelatedFieldListFilter respect ModelAdmin.ordering.
Diffstat (limited to 'django/db')
-rw-r--r--django/db/models/fields/__init__.py4
-rw-r--r--django/db/models/fields/reverse_related.py4
2 files changed, 4 insertions, 4 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 04c7f002bc..fc4966c8b7 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -807,7 +807,7 @@ class Field(RegisterLookupMixin):
return return_None
return str # return empty string
- def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, limit_choices_to=None):
+ def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, limit_choices_to=None, ordering=()):
"""
Return choices with a default blank choices included, for use
as <select> choices for this field.
@@ -828,7 +828,7 @@ class Field(RegisterLookupMixin):
)
return (blank_choice if include_blank else []) + [
(choice_func(x), str(x))
- for x in rel_model._default_manager.complex_filter(limit_choices_to)
+ for x in rel_model._default_manager.complex_filter(limit_choices_to).order_by(*ordering)
]
def value_to_string(self, obj):
diff --git a/django/db/models/fields/reverse_related.py b/django/db/models/fields/reverse_related.py
index 828d79d6ac..eb6b934259 100644
--- a/django/db/models/fields/reverse_related.py
+++ b/django/db/models/fields/reverse_related.py
@@ -114,7 +114,7 @@ class ForeignObjectRel(FieldCacheMixin):
self.related_model._meta.model_name,
)
- def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH):
+ def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, ordering=()):
"""
Return choices with a default blank choices included, for use
as <select> choices for this field.
@@ -123,7 +123,7 @@ class ForeignObjectRel(FieldCacheMixin):
initially for utilization by RelatedFieldListFilter.
"""
return (blank_choice if include_blank else []) + [
- (x.pk, str(x)) for x in self.related_model._default_manager.all()
+ (x.pk, str(x)) for x in self.related_model._default_manager.order_by(*ordering)
]
def is_hidden(self):