How to create a Dropdown Choice filter field in Django using ajax?

I am trying to create dynamically filtered selection fields down, I went through a blog, but it is confusing if anyone can suggest an easy way to do this in django.

I am trying to create a dynamically filtered selection box in Django. I tried the steps described here , but I do not understand this.

How to create a filtered selection field in Django using ajax?

+4
source share
3 answers

You can use dajaxproject (django + ajax). Example: http://www.dajaxproject.com/forms/ It's that simple.

+6
source

Maybe you mean something like this? http://code.google.com/p/django-ajax-selects/

I have it implemented in several projects, and it works well. If you are looking for a kind of search form for foreign keys, take a look at the application I started a few weeks ago:

https://github.com/schneck/django-foreignkeysearch

0
source

I had only a small set of drop-down options that I needed to display, so I decided to be lazy and not go along the Ajax route, but rather used the original example provided on the blog (its prototype). This will slow down the page rendering if you have a lot of drop-down options that I don’t have.

The way this worked for me was that I replaced the array:

modelstxt[1] = "1\tEscort\n2\tTaurus"; modelstxt[2] = "1\tAltima\n2\tMaxima"; 

With template tags that will create the same array when building the page (note that I use locations and areas, not models, and does):

 areastxt[0] = "0\t--"; {% for location in locations %} areastxt[{{location.id}}] = "0\t-- {% for area in areas %} {% if area.location_id == location.id %} \n{{area.id}}\t{{area.name}} {% endif %} {% endfor %}"; {% endfor %} 

Disclaimer: I am noob'ish, so I can commit noob faux-pas using this approach.

0
source

Source: https://habr.com/ru/post/1337789/


All Articles