Custom regex match for filter syntax #1507
-
Is there a way to do custom match patterns for filter query params? For example, instead of using Something like this: import re
match = r"^filter\[([a-zA-Z]+).?([a-zA-Z]+)?\]"
def parse_filter(match, filter):
if not re.match(match, filter):
raise Exception("Invalid filter")
search = re.search(match, filter)
return search.group(1), search.group(2)
query_param = input("Filter > ")
field, lookup_expr = parse_filter(match, query_param)
print(f"Result: " + (f"{field}__{lookup_expr}" if lookup_expr else field)) Here, the Is there a way to do this? Or the default |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This isn't built-in, but see LookupChoiceFilter that does something similar. (You'll need to handle the mapping from the GET QueryDict to the |
Beta Was this translation helpful? Give feedback.
This isn't built-in, but see LookupChoiceFilter that does something similar. (You'll need to handle the mapping from the GET QueryDict to the
filter()
implementation.)