Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 'DateRangeWidget' in widgets.py #1569

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions django_filters/widgets.py
Expand Up @@ -123,8 +123,8 @@ def decompress(self, value):
if value is None:
return [None, None]
return value


class RangeWidget(SuffixedMultiWidget):
template_name = "django_filters/widgets/multiwidget.html"
suffixes = ["min", "max"]
Expand All @@ -138,10 +138,24 @@ def decompress(self, value):
return [value.start, value.stop]
return [None, None]


class DateRangeWidget(RangeWidget):

class DateInput(forms.DateInput):
input_type = 'date'


class DateRangeWidget(SuffixedMultiWidget):
template_name = "django_filters/widgets/multiwidget.html"
suffixes = ["after", "before"]

def __init__(self, attrs=None):
widgets = (DateInput, DateInput)
super().__init__(widgets=widgets, attrs=attrs)

def decompress(self, value):
if value:
return [value.start, value.stop]
return [None, None]


class LookupChoiceWidget(SuffixedMultiWidget):
suffixes = [None, "lookup"]
Expand Down