Hello, my name is Federico Capoano,
I enjoy developing cutting-edge websites
and working with creative people.
27th October 2010 in Coding Tags: django, jquery, programming, python
If you are using Django 1.2 and you tried installing Django Tagging Autocomplete you will have noticed that the autocompletition won't work unless you load a second copy of jQuery.
Loading a second copy of jQuery is quite an inelegant (to use an euphemism) solution and doesn't suit the paradigm of Django.
Because Django 1.2 uses a different jQuery namespace to avoid conflicts with other third party apps.
The fix is easy, just replace the file widgets.py of the tagging_autocomplete app with this code (changes described with two comments):
from django.forms.widgets import Input from django.core.urlresolvers import reverse from django.conf import settings from django.utils.safestring import mark_safe class TagAutocomplete(Input): input_type = 'text' def render(self, name, value, attrs=None): json_view = reverse('tagging_autocomplete-list') html = super(TagAutocomplete, self).render(name, value, attrs) # in the following line I added (django.jQuery); in the end js = u'<script type="text/javascript">(function($) { $("#%s").autocomplete("%s", { multiple: true }); })(django.jQuery);</script>' % (attrs['id'], json_view) return mark_safe("\n".join([html, js])) class Media: js_base_url = getattr(settings, 'TAGGING_AUTOCOMPLETE_JS_BASE_URL','%s/jquery-autocomplete' % settings.MEDIA_URL) css = { 'all': ('%s/jquery.autocomplete.css' % js_base_url,) } js = ( # this line can be removed as Django 1.2 natively includes jQuery - '%s/lib/jquery.js' % js_base_url, '%s/jquery.autocomplete.js' % js_base_url, )
The next step is to replace (jQuery); with (django.jQuery); at the very end of jquery.autocomplete.js.
This change breaks compatibility with Django 1.1 and that's why the author still didn't want to upgrade the app (27 October 2010).
“ nice site i really learn a lot more power to your blog <a href="http://staying-healthy.info">healthy living</a> ”
By health is wealth in Nice Skip Links Appearing on :focus with CSS
“ Very strange bug- thanks for the fix! ”
By Andrew Chart in IE8 doesn't like 1x1px semi-transparent backgrounds
“ Completely agree about keeping it simple, sometimes people try a little too hard ”
By ryan in 10 Effective Business Card Design Tips
“ I just wanted to say that your blog has been really useful. ”
By Kerala in Django: How to Retrieve Query String Parameters
“ Thank you this was exactly what I have been searching for. ”
By Kerala in Django Tagging Autocomplete Tag-It