Opened 10 years ago

Closed 9 years ago

#4415 closed (fixed)

PositiveIntegerField in models.py does not get validation in form_for_model

Reported by: django@… Owned by: oggie_rob
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Negative values do not raise a ValidationError in the form delivered by form_for_model.

One solution would be to create a newforms.PositiveIntegerField class, another would be to just use newforms.IntegerField with a default value of min_value = 0.

Attachments (5)

positiveintegerfield.diff (660 bytes) - added by django@… 10 years ago.
PositiveIntegerField as newforms.IntergerField with min_value
positiveintegerfield2.diff (957 bytes) - added by django@… 10 years ago.
new class: newforms.PositiveIntegerField
positiveintegerfield2.2.diff (945 bytes) - added by Will Hardy <will@…> 10 years ago.
new class: newforms.PositiveIntegerField
4415_fields.diff (1.0 KB) - added by oggie_rob 9 years ago.
formfield method changes to PositiveIntegerField and PositiveSmallIntegerField
4415_tests.diff (973 bytes) - added by oggie_rob 9 years ago.
Test of positive integer values via form_for_model. Used generic "boundary" model which can be extended.

Download all attachments as: .zip

Change History (15)

Changed 10 years ago by django@…

Attachment: positiveintegerfield.diff added

PositiveIntegerField as newforms.IntergerField with min_value

Changed 10 years ago by django@…

Attachment: positiveintegerfield2.diff added

new class: newforms.PositiveIntegerField

comment:1 Changed 10 years ago by Malcolm Tredinnick

Adding yet another newforms field isn't necessary here. We already have IntegerField, as you note and it can supply all the necessary functionality.

Looks like writing a formfield() method for django.db.models.fields.PostiveIntegerField would be the right solution.

Changed 10 years ago by Will Hardy <will@…>

new class: newforms.PositiveIntegerField

comment:2 in reply to:  description Changed 10 years ago by Will Hardy <will@…>

New attachment added after copy and paste error in the positiveintegerfield2.diff

comment:3 in reply to:  1 Changed 10 years ago by Will Hardy <will@…>

Replying to mtredinnick:

Adding yet another newforms field isn't necessary here. We already have IntegerField, as you note and it can supply all the necessary functionality.

Sorry, didn't see this comment before fixing the second patch.

Looks like writing a formfield() method for django.db.models.fields.PostiveIntegerField would be the right solution.

Good, then feel free to ignore/delete positiveintegerfield2.diff and see positiveintegerfield.diff for this change.

comment:4 Changed 10 years ago by django@…

Also, if someone could replace my email address above with django@…, that would be nice.

comment:5 Changed 9 years ago by anonymous

Owner: changed from nobody to anonymous
Status: newassigned

comment:6 Changed 9 years ago by oggie_rob

Owner: changed from anonymous to oggie_rob
Status: assignednew

Changed 9 years ago by oggie_rob

Attachment: 4415_fields.diff added

formfield method changes to PositiveIntegerField and PositiveSmallIntegerField

Changed 9 years ago by oggie_rob

Attachment: 4415_tests.diff added

Test of positive integer values via form_for_model. Used generic "boundary" model which can be extended.

comment:7 Changed 9 years ago by oggie_rob

Status: newassigned

Didn't need to create a new form field, just modified the formfield() method.
Added tests for boundary validation only via form_for_model method.

comment:8 Changed 9 years ago by oggie_rob

The last two patches (named 4415_*) are the only ones you need.

comment:9 Changed 9 years ago by Chris Beaven

Triage Stage: UnreviewedReady for checkin

Normal method is to just have one single patch, but it looks good oggie_rob.

comment:10 Changed 9 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(In [6252]) Fixed #4415 -- Added formfield method to PositiveIntegerField, so that those fields get validated correctly. Thanks, Oggie Rob.

Note: See TracTickets for help on using tickets.
Back to Top