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
Post a Comment