django-advanced-filters icon indicating copy to clipboard operation
django-advanced-filters copied to clipboard

Documentation: Expected Value Format for "One of"

Open mrname opened this issue 7 years ago • 1 comments

It looks like the "one of" operator maps to "iregex" under the hood. Does this mean that the value should be a regular expression? The confusion hit for me when I went to input the value, and it provided an autocomplete field which I was only allowed to select one of (I expected to see an interface that would allow me to choose multiple values). So, should the value of this operator type be a regex?

mrname avatar Jun 11 '18 20:06 mrname

Hi again! You're absolutely right, this is extremely confusing, and better documentation is definitely a good start (to be continued by adding a specialised widget for this operator, as in #23).

The iregex operator is used for "One of" to look up one of any number of results as value. The following test case, for example, will return results where email matches EITHER foo OR bar:

https://github.com/modlinltd/django-advanced-filters/blob/365b646aaf63408dcb9aca2cc0bf1fca54c23780/advanced_filters/tests/test_forms.py#L174

We actually transform the input of this field's value, from a comma separated string of values to this iregex form in the following VaryingTypeCharField class:

https://github.com/modlinltd/django-advanced-filters/blob/6541b533314934d17b7c4c4209d22b4bd66bb1dc/advanced_filters/form_helpers.py#L13

asfaltboy avatar Jun 11 '18 20:06 asfaltboy