[Django] #26834: MinValueValidator/MaxValueValidator not forwarded to form field for ModelForm

53 views
Skip to first unread message

Django

unread,
Jul 4, 2016, 3:30:53 AM7/4/16
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------+-------------------------------------------------
Reporter: sergei- | Owner: nobody
maertens |
Type: Bug | Status: new
Component: Forms | Version: 1.9
Severity: Normal | Keywords: MaxValueValidator,
Triage Stage: | MinValueValidator, ModelForm, IntegerField
Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
I just ran into a possible enhancement.

Consider the following model:

{{{
#!python
DEFAULT_RATING = 50
MAX_RATING = 100
MIN_RATING = 0


class KitReviewPropertyRating(models.Model):
"""
Represents properties for a kit review rated on a scale from
MIN_RATING to MAX_RATING
"""
kit_review = models.ForeignKey('KitReview', related_name='ratings')
prop = models.ForeignKey('KitReviewProperty')
rating = models.PositiveSmallIntegerField(
_('rating'), default=DEFAULT_RATING,
validators=[MinValueValidator(MIN_RATING),
MaxValueValidator(MAX_RATING)]
)
}}}

and the matching ModelForm:
{{{
#!python
from django.forms.widgets import NumberInput


class RangeInput(NumberInput):
input_type = 'range'


class KitReviePropertyRatingForm(forms.ModelForm):

class Meta:
model = KitReviewPropertyRating
fields = ('id', 'prop', 'rating')
widgets = {
'rating': RangeInput(attrs={'max': MAX_RATING})
}
}}}

As you can see, I have to specify the `max` widget attribute manually,
otherwise the html input looks like this: `<input type="range"
name="rating" value="50" min="0">`, instead of the expected `<input
type="range" name="rating" value="50" min="0" max="100">`. I had expected
the Min/MaxValueValidator to be 'forwarded' to the form field (via
`IntegerField.formfield` method), but no such thing happens. #26786 does
add the validators on the model level, based on the db connection used and
the limits there, and only if no such validators were present yet.

I'd like to make it so that Min/MaxValueValidators are translated into
`min_value`/`max_value` defaults for the `IntegerField.formfield` method,
this would be more in line with the expected output and reduce the need to
repeat yourself.

--
Ticket URL: <https://code.djangoproject.com/ticket/26834>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 6, 2016, 10:30:21 PM7/6/16
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: nobody

Type: Bug | Status: new
Component: Forms | Version: 1.9
Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

I'm wary of the additional complexity, but can't say that the request is
unreasonable.

--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:1>

Django

unread,
Jul 21, 2016, 2:01:15 PM7/21/16
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sgzsh269
Type: Bug | Status: assigned
Component: Forms | Version: 1.9

Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sgzsh269):

* owner: nobody => sgzsh269
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:2>

Django

unread,
Jul 22, 2016, 3:41:19 PM7/22/16
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sgzsh269
Type: Bug | Status: assigned
Component: Forms | Version: 1.9

Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sgzsh269):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:3>

Django

unread,
Jul 22, 2016, 4:05:32 PM7/22/16
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sgzsh269
Type: Bug | Status: assigned
Component: Forms | Version: master

Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sgzsh269):

* version: 1.9 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:4>

Django

unread,
Jul 22, 2016, 4:43:04 PM7/22/16
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: sergei-maertens | Owner: sgzsh269
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


Comment:

Comments for improvement on the PR (and some failing tests to be fixed).

--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:5>

Django

unread,
May 3, 2019, 2:48:48 PM5/3/19
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: Sergei Maertens | Owner: Tobias
| Kunze

Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tobias Kunze):

* owner: Sagar Nilesh Shah => Tobias Kunze
* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:6>

Django

unread,
May 8, 2019, 1:42:43 AM5/8/19
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: Sergei Maertens | Owner: Tobias
| Kunze
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:7>

Django

unread,
Feb 10, 2021, 1:24:56 AM2/10/21
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: Sergei Maertens | Owner: Tobias
| Kunze
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

The proposed solution has some side-effects. We should reach a wider
audience and consensus on DevelopersMailingList before moving this
forward.

--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:8>

Django

unread,
Feb 10, 2021, 6:44:53 AM2/10/21
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: Sergei Maertens | Owner: Tobias
| Kunze
Type: Bug | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

#25594 might be related.

--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:9>

Django

unread,
Feb 23, 2023, 2:27:14 AM2/23/23
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: Sergei Maertens | Owner: Tobias
| Kunze
Type: New feature | Status: assigned
Component: Forms | Version: dev

Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* type: Bug => New feature


--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:10>

Django

unread,
Mar 18, 2024, 3:06:12 AM3/18/24
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: Sergei Maertens | Owner: Tobias
| Kunze
Type: New feature | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ülgen Sarıkavak):

* cc: Ülgen Sarıkavak (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:11>

Django

unread,
Mar 9, 2025, 11:13:17 AM3/9/25
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: Sergei Maertens | Owner: Tobias
| Kunze
Type: New feature | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by JaeHyuckSa):

* cc: JaeHyuckSa (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:12>

Django

unread,
Aug 22, 2025, 1:37:57 PM8/22/25
to django-...@googlegroups.com
#26834: MinValueValidator/MaxValueValidator not forwarded to form field for
ModelForm
-------------------------------------+-------------------------------------
Reporter: Sergei Maertens | Owner: Clifford
| Gama
Type: New feature | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: MaxValueValidator, | Triage Stage: Accepted
MinValueValidator, ModelForm, |
IntegerField |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* owner: Tobias Kunze => Clifford Gama

--
Ticket URL: <https://code.djangoproject.com/ticket/26834#comment:13>
Reply all
Reply to author
Forward
0 new messages