mirror of
https://github.com/django/django.git
synced 2025-11-25 05:04:26 +00:00
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>
This commit is contained in:
parent
0b120f5d64
commit
03d0f12c82
8 changed files with 153 additions and 8 deletions
|
|
@ -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>'
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue