django-url-filter
django-url-filter copied to clipboard
CallableFilter.lookups with only custom_lookups
Hi,
for a project that use drf-yasg, i use CallableFilter for model properties that returns queryset. But when doc was generated with drf-yasg, many lookups were generated when I didn't create them.
For now, I override the lookups method like this:
@cached_property
def lookups(self):
r = LOOKUP_CALLABLE_FROM_METHOD_REGEX
custom_lookups = {
m.groupdict()["filter"]
for m in (r.match(i) for i in dir(self))
if m and m.groupdict()["backend"] == self.root.filter_backend.name
}
return custom_lookups
Would there be a possibility to choose that this method only returns the custom lookups?
A parameter custom_lookups_only=False in the __init__ of CallableFilter for example?
CallableFilter overwrites lookups:
https://github.com/miki725/django-url-filter/blob/056828119fa35631ab8d8a9b481f305c3b6c64cc/url_filter/filters.py#L479-L496
sounds like a bug. dont remember if there was any reason for returning all lookups for CallableFilter
Maybe for fields that need some lookups created or overloaded?
I'm not sure it's a bug, maybe we should just automatically detect the field isinstance of Field?
Thanks for your quick reply!