Comments on: Autocomplete in Django #2 http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/ At the core of all well-founded belief lies belief that is unfounded - Wittgenstein Wed, 27 Nov 2013 14:53:00 +0000 hourly 1 https://wordpress.org/?v=5.2.11 By: shiv609 http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/comment-page-1/#comment-21343 Wed, 27 Nov 2013 14:53:00 +0000 http://magicrebirth.wordpress.com/?p=359#comment-21343 When i upgrade to django 1.5.2 (from 1.2.3), this widget is not working. Got the following error in UI (when debug is True):
django widgets.py ‘NoneType’ object has no attribute ‘_registry’

Django has introduced admin_site as one of the arguments for ForeignKeyRawIdWidget __init__() method.

This is the cause for the failure. To fix this, we need to do the following code change:

1. Add admin_site as one of the arugment for FkSearchInput class. Refer line 103:

def __init__(self, rel, admin_site, search_fields, attrs=None):
self.search_fields = search_fields
super(FkSearchInput, self).__init__(rel, admin_site, attrs)

2. Do the above change for NoLookupsForeignKeySearchInput (line no. 181) and InlineSearchInput class (line no. 257) also.

def __init__(self, rel, admin_site, search_fields, attrs=None):
self.search_fields = search_fields
super(NoLookupsForeignKeySearchInput, self).__init__(rel, admin_site, attrs)

def __init__(self, rel, admin_site, search_fields, attrs=None):
self.search_fields = search_fields
super(InlineSearchInput, self).__init__(rel, admin_site, attrs)

3. While calling the widget pass “self.admin_site” as one of the argument in formfield_for_dbfield method.

Changes for FkAutocompleteAdmin class as follows (line no: 439):

kwargs[‘widget’] = FkSearchInput(db_field.rel, self.admin_site, self.related_search_fields[db_field.name])

4. Do the same for NoLookupsForeignKeyAutocompleteAdmin and InlineAutocompleteAdmin class, formfield_for_dbfield method

Once the changes are done, the autocomplete widget will work.

5. In the UI, search icon will be missing because of the admin_media_prefix tag. This tag needs to be replaced with static keyword in all the three (fk, inline, nolookups) html files as follows:

Thats it.

]]>
By: Dominique Guardiola http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/comment-page-1/#comment-145 Mon, 30 Apr 2012 09:28:38 +0000 http://magicrebirth.wordpress.com/?p=359#comment-145 I’m happily using your module for autocomplete in inlines, but for an unknown reason, I’m unable to have autocomplete fkeys in the parent modeladmin, derived from FKAutocompleteAdmin.
So I use django-extensions ForeignKeyAutocompleteAdmin to do this, that’s not DRY at all, but for now it’s the solution I have …

]]>
By: tecnosegugio http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/comment-page-1/#comment-144 Fri, 24 Feb 2012 20:55:37 +0000 http://magicrebirth.wordpress.com/?p=359#comment-144 @mike: sorry for the late answer.
Yes I mean the ‘& amp;’ should be changed into ‘&’.

Now I’m looking how to solve another bug: if I put for a mistake a “non numeric” char in the ID field, the one next the ‘plus’ icon, I get a 500 error:
“Caught ValueError while rendering: invalid literal for int() with base 10: ‘alpha'”.
Looks like there is no validation for that field.

]]>
By: Rawr http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/comment-page-1/#comment-143 Thu, 24 Nov 2011 16:17:41 +0000 http://magicrebirth.wordpress.com/?p=359#comment-143 How can I change width of that field? It’s too small for my needs. Thanks!

]]>
By: mike http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/comment-page-1/#comment-142 Wed, 14 Sep 2011 15:08:42 +0000 http://magicrebirth.wordpress.com/?p=359#comment-142 @Karen: I haven’t tried to replicate the error but it looks like a conflict between the autocomplete module and django’s list_editable widget. This autocomplete solution was developed on django 1.1 – so it may well be that on 1.3 errors like this will crop up… A workaround could be forcing the list_editable widget *not* to be the autocomplete one, as discussed here: http://stackoverflow.com/questions/7065982/list-editable-and-widgets

]]>
By: mike http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/comment-page-1/#comment-141 Wed, 14 Sep 2011 14:56:16 +0000 http://magicrebirth.wordpress.com/?p=359#comment-141 @tecnosegugio Thanks for the tips; however I can’t understand exactly what you mean because (I guess) wordpress has transformed some your characters into html…. did you mean “& amp ;” ? (note the spaces between characters to avoid wordpress to pick it up as html)

]]>
By: Tecnosegugio http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/comment-page-1/#comment-140 Tue, 13 Sep 2011 13:07:59 +0000 http://magicrebirth.wordpress.com/?p=359#comment-140 Whoops…forgot to edit the rows 195 and 271 with the same change: from ‘&’ to ‘&’. Sorry.

]]>
By: Tecnosegugio http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/comment-page-1/#comment-139 Mon, 12 Sep 2011 14:57:23 +0000 http://magicrebirth.wordpress.com/?p=359#comment-139 Another small fix: in autocomplete_admin.py, line 117: the ‘&’ should be changed into ‘&’ otherwise the browser doesn’t understand the URL and ignore the parameters.

]]>
By: Tecnosegugio http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/comment-page-1/#comment-138 Thu, 08 Sep 2011 22:27:41 +0000 http://magicrebirth.wordpress.com/?p=359#comment-138 Just a quick note: with Django 1.3 the extrafilter templatetag can be removed: the “cut” filter already exists in the built-in tag library.

Thank you!

]]>
By: Karen McNeil http://www.michelepasin.org/blog/2009/10/12/autocomplete-in-django-2/comment-page-1/#comment-137 Sat, 13 Aug 2011 03:42:02 +0000 http://magicrebirth.wordpress.com/?p=359#comment-137 Thank you so much for this! I had tried two other autocomplete solutions and they were very complicated and I couldn’t get them to work. This one was so much more straight-forward and works great.

I do have one issue with it, though … It works just like it’s supposed to on the change_form page, but when I make the ForeignKey an list_editable, it doesn’t display properly on the change_list. It shows the box on the right (and you can type the id in that and it will work), but it doesn’t display the box on the left that you can type the word in, which is what I actually need.

Any idea on how I might fix that?

]]>