admin = forms.ModelChoiceField(queryset=Profile.objects.all(),
help_text=_('select an admin for this organization'),
label=_('Organization Admin'),
)
when this form is rendered in a template and I can see a drop-down button on that field and can select an item.
But the number of items is so much that it is very difficult for me to select one.
I want a search option just on top of the drop-down list.
Is it possible? If possible, how?
Part from my code:
from django.contrib.admin.widgets import FilteredSelectMultiple
class WorkForm(forms.Form):
materials = forms.ModelMultipleChoiceField(label=_('Materials'), queryset=Goods.objects.filter(deleted=False), required=False, widget=FilteredSelectMultiple(_('materials'), True))
class Media:
css = {
'all': (
'/static/admin/css/widgets.css',
'/static/css/widgets.css',
)
}
js = [
'/admin/jsi18n/'
]
Or you can use https://github.com/applegrew/django-select2
This django plugin is quite helpful: https://pypi.python.org/pypi/django-simple-autocomplete/
It works with jQuery, so you have to ensure that jQuery is working. You have just follow the four installation steps and adapt your form model.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With