summaryrefslogtreecommitdiff
path: root/django/db/models/fields/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/fields/__init__.py')
-rw-r--r--django/db/models/fields/__init__.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index e248b70ba3..a7ec41bf75 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -15,6 +15,7 @@ from django.core import checks, exceptions, validators
from django.db import connection, connections, router
from django.db.models.constants import LOOKUP_SEP
from django.db.models.query_utils import DeferredAttribute, RegisterLookupMixin
+from django.db.models.utils import get_blank_choice_label
from django.db.utils import NotSupportedError
from django.utils import timezone
from django.utils.choices import (
@@ -39,7 +40,9 @@ from django.utils.translation import gettext_lazy as _
__all__ = [
"AutoField",
+ # RemovedInDjango70Warning
"BLANK_CHOICE_DASH",
+ "BLANK_CHOICE_LABEL",
"BigAutoField",
"BigIntegerField",
"BinaryField",
@@ -81,9 +84,13 @@ class NOT_PROVIDED:
pass
-# The values to use for "blank" in SelectFields. Will be appended to the start
-# of most "choices" lists.
+# RemovedInDjango70Warning: From Django 6.1, the values to use for "blank"
+# in SelectFields will be defined by the below BLANK_CHOICE_LABEL constant.
+# Will be appended to the start of most "choices" lists.
+# BLANK_CHOICE_DASH is still available as a constant in Django 6.1.
BLANK_CHOICE_DASH = [("", "---------")]
+# This allows any app's ready() method to overwrite BLANK_CHOICE_LABEL.
+BLANK_CHOICE_LABEL = _("- Select an option -")
def _load_field(app_label, model_name, field_name):
@@ -1088,7 +1095,7 @@ class Field(RegisterLookupMixin):
def get_choices(
self,
include_blank=True,
- blank_choice=BLANK_CHOICE_DASH,
+ blank_choice=None,
limit_choices_to=None,
ordering=(),
):
@@ -1096,6 +1103,8 @@ class Field(RegisterLookupMixin):
Return choices with a default blank choices included, for use
as <select> choices for this field.
"""
+ if blank_choice is None:
+ blank_choice = [("", get_blank_choice_label())]
if self.choices is not None:
if include_blank:
return BlankChoiceIterator(self.choices, blank_choice)