Using jquery's autocomplete in Django's admin: what about 'inlines'?


I still haven't solved this problem entirely, and I'll tell you why. The issue has been discussed by many people, but probably the first and most influential solution is still Jannis Leidel's 'An autocomplete form widget for ForeignKey model fields'.

Leidel says:

[..] my question is, if this could be done on a more abstract level for enhancing relations. when having a foreignkey, you get the browse-icon (lens) right near the input-field. it´d be awesome to search the relations just by typing something into the field … the autocomplete-functionality should then search the related entries on the basis of the defined search-fields.

Here's a nice screencast of the the result [UPDATE: unfortunately the screencast is not available anymore - instead an unsettling image of mad nazi soldiers]:

Picture 1

Leidel's solution is not a copy-paste type of thing, but it's very useful to study his code so to understand what's going on there, and then replicate it in your specific user-scenario. That's exactly what several people have done.

Nonetheless, reusing is more agile that doing things from scratch, isn't it? So, after a bit of research I reached the conclusion that the most interesting and reusable (meaning, plug-and-play) django implementations of jquery's autocomplete are the following two.

1. The admin extensions section of the django-extensions project on google code

  • PROs: it extends django's raw_input widget, so while you can make use of the autocomplete you can still click on the lens and select the object you want from a new objects-list window (see screencast below). Also, you can enter the id of the object and the autocomplete will fill in straightaway the human-readable form of it (not sure how useful it is, but I like it)
  • CONs: supports only one-2-many relationships, that is, it doesn't work with many2many or inlines5.

2. Another project on google code called - surprise - django-autocomplete !

  • PROs: very compact (just one file, no new apps to include). Works with one2many AND many2many
  • CONs: again, no support for inlines...

After having a go with both of them I decided to use the first one [the admin extensions section of the django-extensions project], cause I don't need many2many support and I really liked the fact that the standard 'raw-id' behaviour is still available.

Here's a nice screencast (by the way I just realized that this one has been made by Jannis Leidel too, so I guess it's sort of an evolution of the previous one) [UPDATE #2: also this screencast is not available anymore! what's going on with mr Leidel?]:

Picture 3

Conclusion: there's only one BIG problem - it doesn't work with inlines out-of-the-box ! I'm looking at extending it now... will keep you posted!

Cite this blog post:


Michele Pasin. Using jquery's autocomplete in Django's admin: what about 'inlines'?. Blog post on www.michelepasin.org. Published on Sept. 30, 2009.

Comments via Github:


See also:

2022


paper  Generating large-scale network analyses of scientific landscapes in seconds using Dimensions on Google BigQuery

International Conference on Science, Technology and Innovation Indicators (STI 2022), Granada, Sep 2022.





2017


paper  Using Linked Open Data to Bootstrap a Knowledge Base of Classical Texts

WHiSe 2017 - 2nd Workshop on Humanities in the Semantic web (colocated with ISWC17), Vienna, Austria, Oct 2017.




2007


paper  Capturing Knowledge About Philosophy

Fourth International Conference on Knowledge Capture (K-CAP07), Whistler, BC, Canada, Oct 2007. pp. 47-54