diff --git a/django_filters/filterset.py b/django_filters/filterset.py index 4cd8e407e..1c72552e6 100644 --- a/django_filters/filterset.py +++ b/django_filters/filterset.py @@ -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 @@ -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): """ @@ -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: