I need a field which should be both a dropdown field and a text field. I should be able to enter new values (or) choose something from the dropdown.
I was expecting "name" to be a dropdown field with all the values from the lookup. But only when I start entering something into the field do the list of values appear. Should I be using a AutoComboboxWidget or AutoComboboxSelectWidget or something else to make this work?
My code is pasted below.
template file
views.py
def fruit(request): if request.method == 'POST': fruitform = FruitForm(request.POST) else: if request.GET: fruitform = FruitForm(initial=request.GET) else: fruitform = FruitForm() return render(request,'fruit.html', {'fruitform': fruitform})
Lookups.py
class FruitLookup(ModelLookup): model = Fruit search_fields = ('name__icontains', ) registry.register(FruitLookup)
forms.py
class FruitForm(forms.Form): name = AutoCompleteSelectField(lookup_class=FruitLookup,label='Fruit',required=False,widget=AutoComboboxSelectWidget)
class Meta(object): model = Fruit widgets = {'name': selectable.AutoComboboxSelectWidget(lookup_class=FruitLookup), } def __init__(self, *args, **kwargs): super(FruitForm, self).__init__(*args, **kwargs)