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

CallableFilter.lookups with only custom_lookups #78

Open
eralumin opened this issue Feb 6, 2019 · 2 comments
Open

CallableFilter.lookups with only custom_lookups #78

eralumin opened this issue Feb 6, 2019 · 2 comments
Labels

Comments

@eralumin
Copy link

eralumin commented Feb 6, 2019

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?

@miki725
Copy link
Owner

miki725 commented Feb 6, 2019

CallableFilter overwrites lookups:

@cached_property
def lookups(self):
"""
Get all supported lookups for the filter
This property is identical to the super implementation except it also
finds all custom lookups from the class methods and adds them to the
set of supported lookups as returned by the super implementation.
"""
lookups = super(CallableFilter, self).lookups
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 lookups | custom_lookups

sounds like a bug. dont remember if there was any reason for returning all lookups for CallableFilter

@miki725 miki725 added the bug label Feb 6, 2019
@eralumin
Copy link
Author

eralumin commented Feb 6, 2019

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants