Wednesday, August 29, 2018

Re: Searchable dropdown from models

If I understand your question, there are many different django projects that offer a solution to "autocomplete" in a form. 


Or, you can roll your own with the addition of some Javascript. Autocomplete is not a "built-in" function withing the django framework.

Hope this helps!

Mark

On Wed, Aug 29, 2018 at 1:02 PM, ah <aseem.hegshetye@gmail.com> wrote:
 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.

--
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/CAEqej2Of1e67iiz1yvta3WpZi3MNSjkx5%2BGQLOA_xKeLUYbvCA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment