Auto-complete: django auto-complete light vs jquery autocomplete

Hey,

I need to provide users with the ability to search in a field and have auto-complete options offered. However I also need additional fields in a form to be filled based on their selection. E.g. say this is a product list, the auto-complete field could be the product name. Once they select the name, description prices & whatever gets filled in subsequent fields in that table/form.

From what I see, both django auto-complete-light and jquery auto-complete could do for my base use case. The application is somewhat large so I’m likely to end up with more use cases for this.

Anyone here has experience with both, or some relevent opinion/source of information as to how they compare and why I would want to favor one over the other? (other than Jquery being part of a much larger project, whereas the the django complete is just an app built by separate team)? Your personal notes/experience with either of them would also be welcomed.

Franck

Hi!

I used Django Autocomplete Light (DAL) and it worked great for my needs. You can check other packages in the autocomplete section of djangopackages.

If product is a model, you could use a DAL ModelSelect2 Widget inside a form and search for products based on their name.

For example:

Form widget

obra-social-all-autocomplete is the url which will be called when you start typing on the select to obtain the obras sociales.

Url

That url maps to ObraSocialAllAutocomplete view.

Autocomplete view

This view checks if the user has a permission, then it searches on the ObraSocial model.
self.q contains the characters you type on the select.

At the end you end up with something like this.

imagen

Maybe it seems complex, but if you need to make several forms with autocomplete functionality, I think it pays off. Just create an autocomplete view, an url and use it in a widget.

1 Like

Thanks for the comment Marco!

However I ended up going with jquery. There are a few upsides that I see with it. I have only prototyped with django-auto-complete, so do take those with a grain of salt.

Jquery is a much wider library

That’s a plus, because if there’s any chances you’ll need to do other javascript-sy stuff (ajax calls etc.) then you’ll already have to manage some sort of javascript code base. Therefore the auto-complete codes will just fit into that organisation. I find it neat. Plus if the auto-complete features I’ve implemented are needed within those other javascript-sy things.

Minimal changes needed on the Django-side

The only thing one needs to change in django is adding endpoints to allow for the ajax calls to be made - so one more entry in urls.py to provide an endpoint, and 1 method in views.py to process the request & return the results (no need really for CBV for this, my methods for this are 3-4 lines or code really).

Jquery is not going anywhere, large documentation/support base

The docs for auto-complete is OK, but it largely relies on examples of code you have to sift through in order to what more advanced uses. I’ve found that for base cases, yes the django app is nice and it also works in the admin view quite easily, however the more complicated the use-case, the easier jquery becomes to use. In other words, the incremental cost in complexity to me as a programmer to do more complicated stuff wrt to auto-complete is much smaller with jquery than with django-autocomplete. I’m already using jquery selectors etc.

1 Like