Skip to content

Commit

Permalink
Update filters.py (andreynovikov#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
cansarigol authored Sep 16, 2020
1 parent eb49748 commit b5275e5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion daterangefilter/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ def __init__(self, field, request, params, model, model_admin, field_path):
if self.lookup_gte and self.lookup_lte:
self.lookup_val = '{} - {}'.format(self.lookup_gte, self.lookup_lte)
# if we are filtering DateTimeField we should add one day to final date
if isinstance(model._meta.get_field(field_path), models.DateTimeField):
if "__" in field_path:
related_model, field = field_path.split("__")
field = model._meta.get_field(related_model).related_model._meta.get_field(field)
else:
field = model._meta.get_field(field_path)

if isinstance(field, models.DateTimeField):
try:
gte_date = datetime.datetime.strptime(self.lookup_gte, '%Y-%m-%d')
lte_date = datetime.datetime.strptime(self.lookup_lte, '%Y-%m-%d')
Expand Down

0 comments on commit b5275e5

Please sign in to comment.