From 1258f9d4519d4aba75dc04802aff1ed1d1eb8d9d Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Tue, 16 Apr 2024 00:11:21 +0200 Subject: [PATCH] Fix JDateFieldListFilter bug with jDateField --- django_jalali/admin/filters.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/django_jalali/admin/filters.py b/django_jalali/admin/filters.py index 1b7a274..d9b7d0b 100644 --- a/django_jalali/admin/filters.py +++ b/django_jalali/admin/filters.py @@ -22,7 +22,9 @@ def __init__(self, field, request, params, model, model_admin, field_path): if isinstance(field, models.jDateTimeField): today = now.replace(hour=0, minute=0, second=0, microsecond=0) + format = "%Y-%m-%d %H:%M:%S" else: + format = "%Y-%m-%d" today = now.date() tomorrow = today + jdatetime.timedelta(days=1) @@ -40,8 +42,8 @@ def __init__(self, field, request, params, model, model_admin, field_path): ( _("Today"), { - self.lookup_kwarg_since: today.strftime("%Y-%m-%d %H:%M:%S"), - self.lookup_kwarg_until: tomorrow.strftime("%Y-%m-%d %H:%M:%S"), + self.lookup_kwarg_since: today.strftime(format), + self.lookup_kwarg_until: tomorrow.strftime(format), }, ), ( @@ -49,26 +51,24 @@ def __init__(self, field, request, params, model, model_admin, field_path): { self.lookup_kwarg_since: ( today - jdatetime.timedelta(days=7) - ).strftime("%Y-%m-%d %H:%M:%S"), - self.lookup_kwarg_until: tomorrow.strftime("%Y-%m-%d %H:%M:%S"), + ).strftime(format), + self.lookup_kwarg_until: tomorrow.strftime(format), }, ), ( _("This month"), { - self.lookup_kwarg_since: (today.replace(day=1)).strftime( - "%Y-%m-%d %H:%M:%S" - ), - self.lookup_kwarg_until: next_month.strftime("%Y-%m-%d %H:%M:%S"), + self.lookup_kwarg_since: (today.replace(day=1)).strftime(format), + self.lookup_kwarg_until: next_month.strftime(format), }, ), ( _("This year"), { self.lookup_kwarg_since: (today.replace(month=1, day=1)).strftime( - "%Y-%m-%d %H:%M:%S" + format ), - self.lookup_kwarg_until: next_year.strftime("%Y-%m-%d %H:%M:%S"), + self.lookup_kwarg_until: next_year.strftime(format), }, ), )