The truth is rarely pure and never simple

grappelli: autocomplete_lookup_fields after Django update

When updating a django project that includes the grappelli app to Django 1.7, grappelli has to be updated, as well. This, however, breaks the autocomplete_lookup_fields keyword for inline selection of foreign key entries. This is because grappelli actually plugs into the django-admin interface of django and uses JavaScript to redirect the user in specific cases.

If you do not fix this issue, then you see the following behaviour: searching for a foreign key object works fine, still opens the new browser window, but once you select the entry, you are offered to edit it in the overlay window. But you rather expect the overlay window to hide, leaving only the ID or the slug of the object to appear in the underlying foreign key selector.

The problem lies in the implementation: the javascript of grappelli has to match the admin interface of django perfectly. While the updates also change the templates of the django admin, you have to update the javascript as well. Long story short, here’s the fix:

python manage.py collectstatic

Be careful here in case you did manual changes to the existing static files, as they will be overwritten.

Leave a comment

Your email address will not be published.