Opened 17 years ago

Closed 17 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: dev
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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@… 17 years ago.
PositiveIntegerField as newforms.IntergerField with min_value
positiveintegerfield2.diff (957 bytes ) - added by django@… 17 years ago.
new class: newforms.PositiveIntegerField
positiveintegerfield2.2.diff (945 bytes ) - added by Will Hardy <will@…> 17 years ago.
new class: newforms.PositiveIntegerField
4415_fields.diff (1.0 KB ) - added by oggie_rob 17 years ago.
formfield method changes to PositiveIntegerField and PositiveSmallIntegerField
4415_tests.diff (973 bytes ) - added by oggie_rob 17 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)

by django@…, 17 years ago

Attachment: positiveintegerfield.diff added

PositiveIntegerField as newforms.IntergerField with min_value

by django@…, 17 years ago

Attachment: positiveintegerfield2.diff added

new class: newforms.PositiveIntegerField

comment:1 by Malcolm Tredinnick, 17 years ago

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.

by Will Hardy <will@…>, 17 years ago

new class: newforms.PositiveIntegerField

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

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

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

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 by django@…, 17 years ago

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

comment:5 by anonymous, 17 years ago

Owner: changed from nobody to anonymous
Status: newassigned

comment:6 by oggie_rob, 17 years ago

Owner: changed from anonymous to oggie_rob
Status: assignednew

by oggie_rob, 17 years ago

Attachment: 4415_fields.diff added

formfield method changes to PositiveIntegerField and PositiveSmallIntegerField

by oggie_rob, 17 years ago

Attachment: 4415_tests.diff added

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

comment:7 by oggie_rob, 17 years ago

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 by oggie_rob, 17 years ago

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

comment:9 by Chris Beaven, 17 years ago

Triage Stage: UnreviewedReady for checkin

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

comment:10 by Russell Keith-Magee, 17 years ago

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