Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultipleChoiceFilter does not use lookup_type #49

Closed
lexotron opened this issue Aug 9, 2011 · 5 comments
Closed

MultipleChoiceFilter does not use lookup_type #49

lexotron opened this issue Aug 9, 2011 · 5 comments

Comments

@lexotron
Copy link

lexotron commented Aug 9, 2011

MultipleChoiceFilter.filter() should be updated to include something along these lines:

def filter(self, qs, value):
    (...)
    lookup = self.lookup_type or 'exact'
    for v in value:
        q |= Q(**{'%s__%s' % (self.name, self.lookup_type): v})
    (...)

I haven't really taken a good look at any of the code, so this is just my initial solution.

@nkryptic
Copy link
Contributor

This is very true and could easily be addressed by the above code. But, should a MultipleChoiceFilter ever perform a non-exact query? Is there a use case for that?

@nkryptic
Copy link
Contributor

Forget the question... I can see possible use cases, although there might be alternatives. Maybe something where the choices are used with an iexect, icontains or iregex? Either way, looks like this should be addressed at some point.

@carltongibson
Copy link
Owner

I'm going to close this as Out of Scope for the moment. Happy to consider documented, tested pull requests. We may have capacity to reconsider in the future.

@rixx
Copy link
Contributor

rixx commented Mar 6, 2019

Is your offer still open? Adding lookup_expr to MultipleChoiceFilter should be a very short PR (think one or two lines, plus tests), and might be useful to more people. I just added it to my project by overriding get_filter_predicate as the class docs suggest, but it took me a while to figure out that I should do this.

@carltongibson
Copy link
Owner

Hey @rixx! Yep. Very happy to look at a PR here. (Thanks! 🤹‍♂️)

carltongibson pushed a commit that referenced this issue Mar 8, 2019
This was requested in #49 (back when lookup_expr was called
lookup_type). This is a minor change, with the added advantage of making
``MultipleChoiceFilter`` perform more like other Filter classes, down to
the explicit ``__exact`` filter.

As the documentation only mentions ``lookup_expr`` to be available on
Filter classes in general, and doesn't mention ``MultipleChoiceFilter``
to be different, no documentation change is necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants