-
Notifications
You must be signed in to change notification settings - Fork 467
Closed
Description
(maybe related to #255)
Hi, I've got some minor problem using templated classes.
When registering an AutocompleteModelTemplate eg:
autocomplete_light.register(LocalUser,
autocomplete_light.AutocompleteModelTemplate,
# Just like in ModelAdmin.search_fields
search_fields=['^givenName', 'sn', 'uid', 'displayName'],
# This will actually html attribute data-placeholder which will set
# javascript attribute widget.autocomplete.placeholder.
autocomplete_js_attributes={'minimum_characters': 1,
},
)
html response from /autocomplete/ url will be:
<span class="div" data-value="ppiselli">
Piero Piselli
</span>
the quickest fix is to override template with something similar:
{% load i18n l10n %}
{% load static %}
{% spaceless %}
<span class="div">
<span data-value="{{ choice.pk|unlocalize }}">{{ choice }}</span>
{% with choice.get_absolute_url as url %}
{% if url %}
<a href="{{ url }}" target="_blank" class="choiceDetail">→</a>
{% endif %}
{% endwith %}
{% with choice.get_absolute_update_url as url %}
{% if url %}
<a href="{{ url }}" target="_blank" class="choiceUpdate">
<img src="{% static 'admin/img/icon_changelink.gif' %}" />
</a>
{% endif %}
{% endwith %}
</span>
{% endspaceless %}
spaceless will do the rest, producing a cleaner:
<span class="div"><span data-value="ppiselli">Piero Piselli</span></span>
This produce better output while maintaining good code readability, and does not break existing javascript
Many thanks for this package, it's great !
ciao,
ale
Metadata
Metadata
Assignees
Labels
No labels