django - how to apply additional filter on the autocomplete_light field based on the paramter passed to __init__() of a model form -


i using django autocomplete_light autocomplete value inserted on foreignkeyfield. want apply filtering on suggestions based upon arguements passed to__init__ method.

this form

class camenuform(autocomplete_light.modelform):   class meta:    model = ca_dispensaries_item    autocomplete_fields = ('item',)  def __init__(self, *args, **kwargs):     self.category = kwargs.pop('category', none)     super(camenuform, self).__init__(*args, **kwargs)     self.fields['item'].queryset=items.objects.filter(product_type__name=self.category)     field_name in self.fields:         field = self.fields.get(field_name)         if field:             field.widget.attrs.update({                 'placeholder': field.label,                 'class': 'form-control'                 }) 

here registry

autocomplete_light.register(items, search_fields=('item_name',)) 

here line in __init__ method doesnt seems work autocomplete. though used filter on here, yet suggestions not filtered.

self.fields['item'].queryset=items.objects.filter(product_type__name=self.category) 


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -