diff --git a/django_mongoengine_filter/filters.py b/django_mongoengine_filter/filters.py index dbfd89c..e388447 100644 --- a/django_mongoengine_filter/filters.py +++ b/django_mongoengine_filter/filters.py @@ -62,45 +62,62 @@ def __init__( self.filter = action self.lookup_type = lookup_type self.widget = widget - self.required = required self.extra = kwargs + self.extra.setdefault('required', False) self.distinct = distinct self.exclude = exclude self.creation_counter = Filter.creation_counter Filter.creation_counter += 1 + # FIXME: original field property + # there had been more logic to check lookup types + # django-filters has renamed lookup_type to lookup_expr + # yet in my case using that smaller `field` property from below works as a glance + # + # @property + # def field(self): + # if not hasattr(self, "_field"): + # help_text = _("This is an exclusion filter") if self.exclude else "" + # if self.lookup_type is None or isinstance( + # self.lookup_type, (list, tuple) + # ): + # if self.lookup_type is None: + # lookup = [(x, x) for x in LOOKUP_TYPES] + # else: + # lookup = [ + # (x, x) for x in LOOKUP_TYPES if x in self.lookup_type + # ] + # self._field = LookupTypeField( + # self.field_class( + # required=self.required, widget=self.widget, **self.extra + # ), + # lookup, + # required=self.required, + # label=self.label, + # help_text=help_text, + # ) + # else: + # self._field = self.field_class( + # required=self.required, + # label=self.label, + # widget=self.widget, + # help_text=help_text, + # **self.extra + # ) + + # return self._field + @property def field(self): - if not hasattr(self, "_field"): - help_text = _("This is an exclusion filter") if self.exclude else "" - if self.lookup_type is None or isinstance( - self.lookup_type, (list, tuple) - ): - if self.lookup_type is None: - lookup = [(x, x) for x in LOOKUP_TYPES] - else: - lookup = [ - (x, x) for x in LOOKUP_TYPES if x in self.lookup_type - ] - self._field = LookupTypeField( - self.field_class( - required=self.required, widget=self.widget, **self.extra - ), - lookup, - required=self.required, - label=self.label, - help_text=help_text, - ) - else: - self._field = self.field_class( - required=self.required, - label=self.label, - widget=self.widget, - help_text=help_text, - **self.extra - ) + if not hasattr(self, '_field'): + field_kwargs = self.extra.copy() + + # TODO: not available in django_mongoengine_filter + # if settings.DISABLE_HELP_TEXT: + # field_kwargs.pop('help_text', None) + self._field = self.field_class(label=self.label, **field_kwargs) return self._field def filter(self, qs, value):