My team has been using "django-jet" as a skin to the admin in our django application.
We have inlines with very large select widgets, so as the django-jet documentation recommends, we added autocomplete
fields to our models.
The problem is that it doesn't support TabularInlines. Inspecting django-jet's code you can see how what to change to make the widget work:
- Copy Django's admin "
tabular.html
" in your template dirs. - Load
jet_tags
in the first line. - Add the filter
jet_select2_lookup
to the fields.
tabular.html
1 {% load i18n admin_urls static admin_modify jet_tags %}
...
...
55 {% if field.is_readonly %}
56 <p>{{ field.contents }}</p>
57 {% else %}
58 {{ field.field.errors.as_ul }}
59 {{ field.field|jet_select2_lookups }}
60 {% endif %}
This approach works to add the autocomplete widget, but it fails with a "invalid option" error.
At the same time, the widget doesn't seems to use the formfield_for_foreignkey
method defined in the admin, so the queryset isn't filtered.
Has anyone successfully added autocomplete to a TabularInline using django-jet?
After a year, maybe I can help you.
See this PR that I made do django-jet:
https://github.com/geex-arts/django-jet/pull/329
It will pass the filters of the form field to the select2 element, which in it's turn will pass those filters to the django-jet, when showing the options. It's working perfectly to me.
Hope it helps.