summaryrefslogtreecommitdiff
path: root/tests/admin_widgets
diff options
context:
space:
mode:
authorHrushikesh Vaidya <hrushikeshrv@gmail.com>2022-02-27 08:26:16 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-28 13:28:21 +0100
commit119f227aa62885f12cd7dd2558a62148d02adbb4 (patch)
tree5bc2a9b5806481ffe2a2751c824bbb0f9143b84e /tests/admin_widgets
parente0442a628eb480eac6a7888aed5a86f83499e299 (diff)
downloaddjango-119f227aa62885f12cd7dd2558a62148d02adbb4.tar.gz
Fixed #33524 -- Allowed overriding empty_label for ForeignKey in ModelAdmin.radio_fields.
Diffstat (limited to 'tests/admin_widgets')
-rw-r--r--tests/admin_widgets/tests.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py
index db724b4196..cce759a9c8 100644
--- a/tests/admin_widgets/tests.py
+++ b/tests/admin_widgets/tests.py
@@ -21,6 +21,7 @@ from django.db.models import (
CharField,
DateField,
DateTimeField,
+ ForeignKey,
ManyToManyField,
UUIDField,
)
@@ -141,6 +142,17 @@ class AdminFormfieldForDBFieldTests(SimpleTestCase):
)
self.assertIsNone(ff.empty_label)
+ def test_radio_fields_foreignkey_formfield_overrides_empty_label(self):
+ class MyModelAdmin(admin.ModelAdmin):
+ radio_fields = {"parent": admin.VERTICAL}
+ formfield_overrides = {
+ ForeignKey: {"empty_label": "Custom empty label"},
+ }
+
+ ma = MyModelAdmin(Inventory, admin.site)
+ ff = ma.formfield_for_dbfield(Inventory._meta.get_field("parent"), request=None)
+ self.assertEqual(ff.empty_label, "Custom empty label")
+
def test_many_to_many(self):
self.assertFormfield(Band, "members", forms.SelectMultiple)