From c96ad0d9f1a57e52b187613d05f11229816797f3 Mon Sep 17 00:00:00 2001 From: Christian Kreuzberger Date: Tue, 17 Oct 2017 16:29:31 +0200 Subject: [PATCH] get_filter_name is now a classmethod, allowing it to be overriden for each FilterClass, addressing issue #774 (#775) --- django_filters/filterset.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) 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: