diff options
Diffstat (limited to 'django/db/models')
| -rw-r--r-- | django/db/models/fields/__init__.py | 4 | ||||
| -rw-r--r-- | django/db/models/fields/reverse_related.py | 4 |
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): |
