Skip to content

Commit

Permalink
get_filter_name is now a classmethod, allowing it to be overriden for…
Browse files Browse the repository at this point in the history
… each FilterClass, addressing issue #774 (#775)
  • Loading branch information
ChristianKreuzberger authored and carltongibson committed Oct 19, 2017
1 parent c562ab8 commit c96ad0d
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions django_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@
)


def get_filter_name(field_name, lookup_expr):
"""
Combine a field name and lookup expression into a usable filter name.
Exact lookups are the implicit default, so "exact" is stripped from the
end of the filter name.
"""
filter_name = LOOKUP_SEP.join([field_name, lookup_expr])

# This also works with transformed exact lookups, such as 'date__exact'
_exact = LOOKUP_SEP + 'exact'
if filter_name.endswith(_exact):
filter_name = filter_name[:-len(_exact)]

return filter_name


def _together_valid(form, fieldset):
field_presence = [
form.cleaned_data.get(field) not in EMPTY_VALUES
Expand Down Expand Up @@ -285,6 +269,22 @@ def get_fields(cls):

return OrderedDict(fields)

@classmethod
def get_filter_name(cls, field_name, lookup_expr):
"""
Combine a field name and lookup expression into a usable filter name.
Exact lookups are the implicit default, so "exact" is stripped from the
end of the filter name.
"""
filter_name = LOOKUP_SEP.join([field_name, lookup_expr])

# This also works with transformed exact lookups, such as 'date__exact'
_exact = LOOKUP_SEP + 'exact'
if filter_name.endswith(_exact):
filter_name = filter_name[:-len(_exact)]

return filter_name

@classmethod
def get_filters(cls):
"""
Expand Down Expand Up @@ -314,7 +314,7 @@ def get_filters(cls):
continue

for lookup_expr in lookups:
filter_name = get_filter_name(field_name, lookup_expr)
filter_name = cls.get_filter_name(field_name, lookup_expr)

# If the filter is explicitly declared on the class, skip generation
if filter_name in cls.declared_filters:
Expand Down

0 comments on commit c96ad0d

Please sign in to comment.