mirror of
https://github.com/django/django.git
synced 2025-10-27 07:36:08 +00:00
[3.2.x] 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. Backport ofceb4b9ee68from main Backport of03d0f12c82from main 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>
This commit is contained in:
committed by
Carlton Gibson
parent
6b020f3c94
commit
a8fef6daaf
@@ -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>'
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user