diff --git a/sigi/apps/utils/filters.py b/sigi/apps/utils/filters.py index 7bc0a18..eea3233 100644 --- a/sigi/apps/utils/filters.py +++ b/sigi/apps/utils/filters.py @@ -251,13 +251,32 @@ class DateRangeFilter(admin.FieldListFilter): "query_string": changelist.get_query_string( remove=self.lookup_kwargs ), - "form": self.get_date_form(self.used_parameters), + "form": self.get_date_form(self.used_parameters, changelist), } ] - def get_date_form(self, context={}): + def get_date_form(self, context={}, changelist=None): date_fields = { - name: forms.DateField(required=False) for name in self.lookup_kwargs + name: forms.DateField( + required=False, + label=(_("De") if "__gte" in name else _("Até")), + widget=forms.DateInput( + attrs={ + "class": "datepicker admin_filter", + "placeholder": ( + _("De") if "__gte" in name else _("Até") + ), + "data-clear": changelist.get_query_string( + remove=[ + name, + ] + ) + if changelist + else "", + } + ), + ) + for name in self.lookup_kwargs } DateForm = type("DateForm", (forms.Form,), date_fields) diff --git a/sigi/apps/utils/templates/admin/date_range_filter.html b/sigi/apps/utils/templates/admin/date_range_filter.html index c3ee1ec..9afb7b2 100644 --- a/sigi/apps/utils/templates/admin/date_range_filter.html +++ b/sigi/apps/utils/templates/admin/date_range_filter.html @@ -1,13 +1,11 @@ {% load i18n %} {% with choice=choices.0 %}