Skip to content

Add RelatedAllFilter? #85

Closed
Closed
@rpkilby

Description

@rpkilby

A current limitation is that you cannot use AllLookupsFilter in conjunction with RelatedFilter. The following obviously does not work, as the declared filters will overwrite each other:

class FooFilter(FilterSet):
    bar = RelatedFilter()
    bar = AllLookupsFilter()

    class Meta:
        model = Foo

You cannot use the '__all__' shortcut for the dict-style syntax either, as it's just a shorthand for the declarative style above.
edit: the next release of django-filter will allow '__all__' to be reimplemented, solving a couple of issues. This still doesn't fix the declarative case though.

A workaround is to use the dict-style syntax without '__all__'. eg,

class FooFilter(FilterSet):
    bar = RelatedFilter()

    class Meta:
        model = Foo
        fields = {
            'bar': ['exact', 'lt', 'gt'],
        }

Including 'exact' does not matter here, as generated filters will not overwrite declared filters (which would be the RelatedFilter in this case.

We could add a RelatedAllFilter, AllLookupsRelatedFilter, AllLookupsWithRelatedFilter, or something along those lines that combines the behavior of both AllLookupsFilter and RelatedFilter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions