Skip to content

Commit

Permalink
Fix JDateFieldListFilter bug with jDateField (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
hramezani authored Apr 18, 2024
1 parent cb7a5e9 commit f9c2a72
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions django_jalali/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -40,35 +42,33 @@ 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),
},
),
(
_("Past 7 days"),
{
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),
},
),
)
Expand Down

0 comments on commit f9c2a72

Please sign in to comment.