Select box is is replaced with Select2 style, but clicking it does not
show the select list.
**model.py**
{{{#!python
class Item(models.Model):
name = models.CharField(max_length=100)
class Category(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class LineItem(models.Model):
item = models.ForeignKey(
'Item',
on_delete=models.CASCADE
)
category = models.ForeignKey(
'Category',
on_delete=models.CASCADE
)
}}}
**admin.py**
{{{#!python
class LineItemInline(admin.TabularInline):
model = LineItem
extra = 1
autocomplete_fields = ('category',)
@admin.register(Item)
class ItemAdmin(admin.ModelAdmin):
list_display = ('name',)
search_fields = ('name',)
inlines = [
LineItemInline
]
@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
list_display = ('name',)
search_fields = ('name',)
}}}
== Github repo
With demo and instructions on how to reproduce
https://github.com/gotling/bug-django2-autocomplete
--
Ticket URL: <https://code.djangoproject.com/ticket/28871>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "screenshot" added.
Inline
* stage: Unreviewed => Accepted
Comment:
I was able to reproduce, but only for new forms added by clicking on the
"Add another ..." link.
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:1>
* cc: Johannes Hoppe (added)
* severity: Normal => Release blocker
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:2>
* owner: nobody => Johannes Hoppe
* status: new => assigned
Comment:
Might I just say: This is an amazing bug report! I'll look into it this
weekend, thanks :)
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:3>
Comment (by Tim Graham):
The Django 2.0 release is scheduled for today so maybe me or somebody else
would look at the issue if you don't have time today.
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:4>
Comment (by Tim Graham):
I found that this patch will allow the "Add another" autocomplete widgets
to work, except for the first one that's added.
{{{ #!diff
diff --git a/django/contrib/admin/static/admin/js/autocomplete.js
b/django/contr
index 15321f9..2fa1920 100644
--- a/django/contrib/admin/static/admin/js/autocomplete.js
+++ b/django/contrib/admin/static/admin/js/autocomplete.js
@@ -29,10 +29,7 @@
$(document).on('formset:added', (function() {
return function(event, $newFormset) {
- var $widget = $newFormset.find('.admin-autocomplete');
- // Exclude already initialized Select2 inputs.
- $widget = $widget.not('.select2-hidden-accessible');
- return init($widget);
+ return $newFormset.find('.admin-
autocomplete').djangoAdminSelect2()
};
})(this));
}(django.jQuery));
}}}
It looks like the contents of `$newFormset` for the first "add another" is
different from the contents of subsequent "add anothers".
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:5>
* owner: Johannes Hoppe => Tim Graham
Comment:
I think a have a working patch and am writing a test.
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:6>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/9406 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"81057645f61fe545f4f11737dbd3040043ed2436" 81057645]:
{{{
#!CommitTicketReference repository=""
revision="81057645f61fe545f4f11737dbd3040043ed2436"
Fixed #28871 -- Fixed initialization of autocomplete widgets in "Add
another" inlines.
Also allowed autocomplete widgets to work on AdminSites with a name other
than 'admin'.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"63d425c679423f14a60b5b1bc1b2a59dc28ec42b" 63d425c6]:
{{{
#!CommitTicketReference repository=""
revision="63d425c679423f14a60b5b1bc1b2a59dc28ec42b"
[2.0.x] Fixed #28871 -- Fixed initialization of autocomplete widgets in
"Add another" inlines.
Also allowed autocomplete widgets to work on AdminSites with a name other
than 'admin'.
Backport of 81057645f61fe545f4f11737dbd3040043ed2436 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"7664fe275910bb31fcca2d54844bedde19fc4ed9" 7664fe2]:
{{{
#!CommitTicketReference repository=""
revision="7664fe275910bb31fcca2d54844bedde19fc4ed9"
Refs #28871 -- Fixed admin_views selenium test failure.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:10>
Comment (by Tim Graham <timograham@…>):
In [changeset:"dbdf5deab07d879146e106724d9ad80e9064c4f5" dbdf5dea]:
{{{
#!CommitTicketReference repository=""
revision="dbdf5deab07d879146e106724d9ad80e9064c4f5"
[2.0.x] Refs #28871 -- Fixed admin_views selenium test failure.
Backport of 7664fe275910bb31fcca2d54844bedde19fc4ed9 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:11>