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

Fix 1275: Make MaxValueValidator default an integer #1276

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion django_filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,16 @@ class ModelMultipleChoiceFilter(QuerySetRequestMixin, MultipleChoiceFilter):
class NumberFilter(Filter):
field_class = forms.DecimalField

def __init__(self, *args, **kwargs):
self.max_value = kwargs.get('max_value', int(1e50))
super().__init__(*args, **kwargs)

def get_max_validator(self):
"""
Return a MaxValueValidator for the field, or None to disable.
"""
return MaxValueValidator(1e50)
if self.max_value is not None:
return MaxValueValidator(self.max_value)

@property
def field(self):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,7 @@ class Meta:
self.assertFalse(f.is_valid())
self.assertEqual(
f.errors,
{'average_rating': ['Ensure this value is less than or equal to 1e+50.']}
{'average_rating': [
'Ensure this value is less than or equal to %d.' % int(1e50)
]}
)