django-selectable icon indicating copy to clipboard operation
django-selectable copied to clipboard

missing filter in get_item to find correct item

Open TZanke opened this issue 8 years ago • 1 comments

I have the following problem. I need the query_parameters to get the correct item in get_item. atm it does not look like if it is supported. So i implemented this workaround:

class CustomWidget(AutoComboboxSelectWidget):
    def update_query_parameters(self, qs_dict):
        self.lookup_class.custom_filter.update(qs_dict)
        super(AutoComboboxSelect, self).update_query_parameters(qs_dict)
class ABCLookup(ModelLookup):
    custom_filter = dict()
    def get_item(self, value):
        return self.get_queryset().filter(**self.custom_filter).get(number=value)

Works, but good idea? Any other solution?

TZanke avatar Jul 14 '17 13:07 TZanke

Hmm. get_item is used by the field's to_python method as well and the request isn't really available there. I'm not sure it can be that strictly enforced but maybe I'm forgetting something.

mlavin avatar Jul 18 '17 13:07 mlavin