diff options
| author | Johannes Maron <info@johanneshoppe.com> | 2021-03-18 11:21:23 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2021-03-18 11:21:23 +0100 |
| commit | 03d0f12c823239812da21e5180aaa74dc6fd146e (patch) | |
| tree | 90aeb14f7d703b552c7ab645dbd82f08960189a4 /tests/admin_widgets/tests.py | |
| parent | 0b120f5d649fb21bb898a8b834b6b33e4cdd9504 (diff) | |
Fixed #32466 -- Corrected autocomplete to_field resolution for complex cases.
In MTI or ForeignKey as primary key cases, it is required to fetch the attname
from the field instance on the remote model in order to reliably resolve the
to_field_name.
Co-authored-by: Johannes Maron <info@johanneshoppe.com>
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Co-authored-by: Carlton Gibson <carlton.gibson@noumenal.es>
Diffstat (limited to 'tests/admin_widgets/tests.py')
| -rw-r--r-- | tests/admin_widgets/tests.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 3c41d9cdfa..f701f1abff 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -24,7 +24,7 @@ from django.utils import translation from .models import ( Advisor, Album, Band, Bee, Car, Company, Event, Honeycomb, Individual, Inventory, Member, MyFileField, Profile, School, Student, - UnsafeLimitChoicesTo, + UnsafeLimitChoicesTo, VideoStream, ) from .widgetadmin import site as widget_admin_site @@ -624,7 +624,17 @@ class ForeignKeyRawIdWidgetTest(TestCase): self.assertHTMLEqual( w.render('test', None), '<input type="text" name="test" class="vForeignKeyRawIdAdminField">\n' - '<a href="/admin_widgets/band/?name=%22%26%3E%3Cescapeme&_to_field=id" ' + '<a href="/admin_widgets/band/?name=%22%26%3E%3Cescapeme&_to_field=artist_ptr" ' + 'class="related-lookup" id="lookup_id_test" title="Lookup"></a>' + ) + + def test_render_fk_as_pk_model(self): + rel = VideoStream._meta.get_field('release_event').remote_field + w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site) + self.assertHTMLEqual( + w.render('test', None), + '<input type="text" name="test" class="vForeignKeyRawIdAdminField">\n' + '<a href="/admin_widgets/releaseevent/?_to_field=album" ' 'class="related-lookup" id="lookup_id_test" title="Lookup"></a>' ) |
