|
15 | 15 | from django.db import connection, connections, router |
16 | 16 | from django.db.models.constants import LOOKUP_SEP |
17 | 17 | from django.db.models.query_utils import DeferredAttribute, RegisterLookupMixin |
| 18 | +from django.db.models.utils import get_blank_choice_label |
18 | 19 | from django.db.utils import NotSupportedError |
19 | 20 | from django.utils import timezone |
20 | 21 | from django.utils.choices import ( |
|
39 | 40 |
|
40 | 41 | __all__ = [ |
41 | 42 | "AutoField", |
| 43 | + # RemovedInDjango70Warning |
42 | 44 | "BLANK_CHOICE_DASH", |
| 45 | + "BLANK_CHOICE_LABEL", |
43 | 46 | "BigAutoField", |
44 | 47 | "BigIntegerField", |
45 | 48 | "BinaryField", |
@@ -81,9 +84,13 @@ class NOT_PROVIDED: |
81 | 84 | pass |
82 | 85 |
|
83 | 86 |
|
84 | | -# The values to use for "blank" in SelectFields. Will be appended to the start |
85 | | -# of most "choices" lists. |
| 87 | +# RemovedInDjango70Warning: From Django 6.1, the values to use for "blank" |
| 88 | +# in SelectFields will be defined by the below BLANK_CHOICE_LABEL constant. |
| 89 | +# Will be appended to the start of most "choices" lists. |
| 90 | +# BLANK_CHOICE_DASH is still available as a constant in Django 6.1. |
86 | 91 | BLANK_CHOICE_DASH = [("", "---------")] |
| 92 | +# This allows any app's ready() method to overwrite BLANK_CHOICE_LABEL. |
| 93 | +BLANK_CHOICE_LABEL = _("- Select an option -") |
87 | 94 |
|
88 | 95 |
|
89 | 96 | def _load_field(app_label, model_name, field_name): |
@@ -1088,14 +1095,16 @@ def _db_default_expression(self): |
1088 | 1095 | def get_choices( |
1089 | 1096 | self, |
1090 | 1097 | include_blank=True, |
1091 | | - blank_choice=BLANK_CHOICE_DASH, |
| 1098 | + blank_choice=None, |
1092 | 1099 | limit_choices_to=None, |
1093 | 1100 | ordering=(), |
1094 | 1101 | ): |
1095 | 1102 | """ |
1096 | 1103 | Return choices with a default blank choices included, for use |
1097 | 1104 | as <select> choices for this field. |
1098 | 1105 | """ |
| 1106 | + if blank_choice is None: |
| 1107 | + blank_choice = [("", get_blank_choice_label())] |
1099 | 1108 | if self.choices is not None: |
1100 | 1109 | if include_blank: |
1101 | 1110 | return BlankChoiceIterator(self.choices, blank_choice) |
|
0 commit comments