django-url-filter icon indicating copy to clipboard operation
django-url-filter copied to clipboard

CallableFilter.lookups with only custom_lookups

Open vesperrin opened this issue 6 years ago • 2 comments

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?

vesperrin avatar Feb 06 '19 14:02 vesperrin

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

miki725 avatar Feb 06 '19 14:02 miki725

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!

vesperrin avatar Feb 06 '19 14:02 vesperrin