mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #32545 -- Improved admin widget for raw_id_fields for UUIDFields.
Co-Authored-By: Jerome Leclanche <jerome@leclan.ch>
This commit is contained in:
parent
ed2018037d
commit
05e29da421
3 changed files with 22 additions and 11 deletions
|
@ -26,7 +26,7 @@ from django.utils import translation
|
|||
|
||||
from .models import (
|
||||
Advisor, Album, Band, Bee, Car, Company, Event, Honeycomb, Individual,
|
||||
Inventory, Member, MyFileField, Profile, School, Student,
|
||||
Inventory, Member, MyFileField, Profile, ReleaseEvent, School, Student,
|
||||
UnsafeLimitChoicesTo, VideoStream,
|
||||
)
|
||||
from .widgetadmin import site as widget_admin_site
|
||||
|
@ -538,19 +538,27 @@ class ForeignKeyRawIdWidgetTest(TestCase):
|
|||
band.album_set.create(
|
||||
name='Hybrid Theory', cover_art=r'albums\hybrid_theory.jpg'
|
||||
)
|
||||
rel = Album._meta.get_field('band').remote_field
|
||||
|
||||
w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site)
|
||||
rel_uuid = Album._meta.get_field('band').remote_field
|
||||
w = widgets.ForeignKeyRawIdWidget(rel_uuid, widget_admin_site)
|
||||
self.assertHTMLEqual(
|
||||
w.render('test', band.uuid, attrs={}),
|
||||
'<input type="text" name="test" value="%(banduuid)s" '
|
||||
'class="vForeignKeyRawIdAdminField">'
|
||||
'class="vForeignKeyRawIdAdminField vUUIDField">'
|
||||
'<a href="/admin_widgets/band/?_to_field=uuid" class="related-lookup" '
|
||||
'id="lookup_id_test" title="Lookup"></a> <strong>'
|
||||
'<a href="/admin_widgets/band/%(bandpk)s/change/">Linkin Park</a>'
|
||||
'</strong>' % {'banduuid': band.uuid, 'bandpk': band.pk}
|
||||
)
|
||||
|
||||
rel_id = ReleaseEvent._meta.get_field('album').remote_field
|
||||
w = widgets.ForeignKeyRawIdWidget(rel_id, widget_admin_site)
|
||||
self.assertHTMLEqual(
|
||||
w.render('test', None, attrs={}),
|
||||
'<input type="text" name="test" class="vForeignKeyRawIdAdminField">'
|
||||
'<a href="/admin_widgets/album/?_to_field=id" class="related-lookup" '
|
||||
'id="lookup_id_test" title="Lookup"></a>',
|
||||
)
|
||||
|
||||
def test_relations_to_non_primary_key(self):
|
||||
# ForeignKeyRawIdWidget works with fields which aren't related to
|
||||
# the model's primary key.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue