Comments have been closed for this post.
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).
Comments have been closed for this post.
“ I got very good results with this, thanks for sharing. ”
By Yasir Atabani in How to speed up tests with Django and PostgreSQL
“ Hi Amad, for any question regarding OpenWISP, use one of the support channels: http://openwisp.org/support.html ”
By Federico Capoano in How to install OpenWISP
“ Sir please guid , i have install the ansible-openwisp2 , now how to add the access points . What is the next procedure . Please help. ”
By Ahmad in How to install OpenWISP
“ Hi Ronak, for any question regarding OpenWISP, use one of the support channels: http://openwisp.org/support.html ”
By Federico Capoano in netjsonconfig: convert NetJSON to OpenWRT UCI
“ Hi, I have installed openwisp controller using ansible playbook. Now, i am adding the configurations automatically using OPENWRT devices in openwisp file by specifying shared_key so can you suggest me if I want to set limit to add configuration how can i do it? ”
By Ronak in netjsonconfig: convert NetJSON to OpenWRT UCI