diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index c7d5db209e..a6d49bbce6 100644
a
|
b
|
def get_context(self, name, value, attrs):
|
157 | 157 | css_class = "vForeignKeyRawIdAdminField" |
158 | 158 | if isinstance(self.rel.get_related_field(), UUIDField): |
159 | 159 | css_class += " vUUIDField" |
160 | | context["widget"]["attrs"].setdefault("class", css_class) |
| 160 | if "class" in context["widget"]["attrs"]: |
| 161 | context["widget"]["attrs"]["class"] += f" {css_class}" |
| 162 | else: |
| 163 | context["widget"]["attrs"]["class"] = css_class |
161 | 164 | else: |
162 | 165 | context["related_url"] = None |
163 | 166 | if context["widget"]["value"]: |
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py
index 70b1233ef4..2c2318b28e 100644
a
|
b
|
def test_render_fk_as_pk_model(self):
|
757 | 757 | 'class="related-lookup" id="lookup_id_test" title="Lookup"></a>', |
758 | 758 | ) |
759 | 759 | |
| 760 | def test_includes_class_override(self): |
| 761 | rel = ReleaseEvent._meta.get_field("album").remote_field |
| 762 | attrs = {"class": "myClass"} |
| 763 | w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site, attrs=attrs) |
| 764 | self.assertHTMLEqual( |
| 765 | w.render("test", None), |
| 766 | '<input type="text" name="test" class="myClass vForeignKeyRawIdAdminField">' |
| 767 | '<a href="/admin_widgets/album/?_to_field=id" class="related-lookup" ' |
| 768 | 'id="lookup_id_test" title="Lookup"></a>', |
| 769 | ) |
| 770 | |
760 | 771 | |
761 | 772 | @override_settings(ROOT_URLCONF="admin_widgets.urls") |
762 | 773 | class ManyToManyRawIdWidgetTest(TestCase): |