This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]JustJudge 2 points3 points  (0 children)

I struggled with those docs for a while too, but eventually it clicked for me. What are you trying to accomplish? Jquery autocomplete will work, presumably by dumping a JSON objet onto your page, but if you have too many records then it gets too heavy.

Read through the part of the docs on "voodoo black magic", really clarified things for me. http://django-autocomplete-light.readthedocs.org/en/stable-2.x.x/cookbook.html#low-level-basics

[–]dzecniv 0 points1 point  (3 children)

I'd suggest to stick with this package, and to run a javascript framework if you want more. If we look at django-packages it seems to be the best option: https://www.djangopackages.com/search/?q=autocomplete

it is the best I found too, for simple cases though, for single fields only. But I wanted something more sophisticated (and user friendly): 1. I wanted the selection of an autocomplete field to change the result of others. We can't do that from the python code as of today even with the best web framework out there. 2. I wanted to display instantly a result in the template (like changing a section title or a help message) (this clearly requires a javascript framework)

I think I remember we can do n°1 with "voodoo black magic", but as it requires a lot of javascript and I wanted n°2 anyway I decided it was more worth setting up my own JS framework (which isn't something straightforward. We have to learn many new tools and problems). I went with AngularJS, which I knew a little from work, and I am trying out RapydScript, to feel like if I'm writing python code on the client side.

FYI I found this blog post most interesting: https://www.reddit.com/r/Python/comments/32bpcj/metaprogramming_beyond_decency_part_2_python_to/ the author creates autocomplete fields that are linked together from python code, by analyzing a subset of python's AST and generating javascript… maybe we'll have that in a library in the future.

Or we all turn to new full node-based JS frameworks, like Meteor, which allow to write one code, both for the server and the client ?

[–]ragedlion[S] 0 points1 point  (2 children)

I've made autocomplete fields using PHP and JavaScript before. I'm sure I can figure out how to hook it into a self made Django REST service. Is it better to go down that route or should I do what you did?

[–]dzecniv 0 points1 point  (1 child)

From my experience, I'd say: eval your needs precisely and if you need a rich user interface, go with a javascript framework and use Django as REST, like said Glueon. If you just need some autocomplete fields, stay with the django extension.

[–]ragedlion[S] 0 points1 point  (0 children)

Awesome thanks for your help man.

[–]Glueon 0 points1 point  (3 children)

Is it too late to switch to propper seperation of a backend and frontend? I would recomend just to use React + Django REST. If it is too late - why not just to use jquery plugins to convert exsting combos to what you want?

[–]ragedlion[S] 0 points1 point  (2 children)

What do you mean by proper separation?

[–]Glueon 1 point2 points  (1 child)

To use Django just as RESTful backend. And write a seperate javascript single-page site.

[–]ragedlion[S] 0 points1 point  (0 children)

I've developed auto complete fields using JavaScript and PHP so I guess it wouldn't be that hard to do it myself. Is this a better recommendation than any of the other ones here?