Tagging Autocomplete to work with Django 1.2

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. 

Why do I get "$ is undefined", "jQuery is undefined"?

Because Django 1.2 uses a different jQuery namespace to avoid conflicts with other third party apps.

How to solve that?

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.

Why tagging autocomplete hasn't been updated yet

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).



Leave your comment


Let's be social

Popular posts

Latest Comments

  1. When I ߋriginalⅼy commented I seem to have clicked the -Notify me when new comments aгe added- checkbox and from now on each time a comment іs adԁed I get 4 emails wіth the same comment. Ⲣerhaps there is an easy method you can remove ...

    By youjizz in Django Tagging Autocomplete Tag-It

  2. Hey there I am so thrilled I found your weƄ site, I really found you by accident, whiⅼe I was reseɑrϲhing on Digg for something else, Nonetheless I am here now and woսld jսst like to say many tһanks fοг a tremendous post and a ...

    By youporn in Django Tagging Autocomplete Tag-It

  3. Sexy photo galleries, daily updated pics http://upload.porn.hotblognetwork.com/?anna breast boob tit nipple porn hair style porn bb08 australia porn fee porn no signon man in a relationship view porn

    By barbarakc3 in OpenWISP at IETF Bangkok

  4. Girls of Desire: All babes in one place, crazy, art http://black.lesbians.bestsexyblog.com/?dominique porn movies harry potter lesbiand porn videos free lesbain porn vedios free porn movie dumps teen bi porn

    By lorraineum16 in OpenWISP at IETF Bangkok

  5. Sexy photo galleries, daily updated pics http://dating.service.xblognetwork.com/?denisse spy toilet poop porn long pron free movies the fastest porn torrent quicktime free lesbian porn alice 3d porn

    By alanawy11 in OpenWISP at IETF Bangkok

Popular Tags

battlemesh censorship creativity criptography django event fosdem google-summer-of-code ibiza inspiration javascript jquery linux nemesisdesign netjson ninux nodeshot open-source openwisp openwrt performance photo programming python security staticgenerator talk upload wifi wireless-community