Wednesday, August 29, 2018

Searchable dropdown from models

 Hi,
I am trying to create a searchable dropdown list  based on Django's model. I have a model M that has 6 objects [apple,orange,carrot,banana,kiwi,peach].
I want to create a view that will have a search box like a html datalist. when user types in "app" -- apple should show in dropbox list. then as user clicks on apple, the form should send id of object apple to the view.

I am using forms.py with
forms.ModelChoiceField(queryset=M.objects.all()

which gives me a dropdown list. But i am unable to implement a search box.
Not much documentation is found online about this issue. Is there a better approach?

Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f03463ee-3b09-4097-b2e3-cfff6d9fa255%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment