Opened 18 years ago
Closed 17 years ago
#4415 closed (fixed)
PositiveIntegerField in models.py does not get validation in form_for_model
Reported by: | 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)
Change History (15)
by , 18 years ago
Attachment: | positiveintegerfield.diff added |
---|
by , 18 years ago
Attachment: | positiveintegerfield2.diff added |
---|
new class: newforms.PositiveIntegerField
follow-up: 3 comment:1 by , 18 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 , 18 years ago
Attachment: | positiveintegerfield2.2.diff added |
---|
new class: newforms.PositiveIntegerField
comment:2 by , 18 years ago
New attachment added after copy and paste error in the positiveintegerfield2.diff
comment:3 by , 18 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 , 18 years ago
Also, if someone could replace my email address above with django@…, that would be nice.
comment:5 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
by , 17 years ago
Attachment: | 4415_fields.diff added |
---|
formfield method changes to PositiveIntegerField and PositiveSmallIntegerField
by , 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 , 17 years ago
Status: | new → assigned |
---|
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:9 by , 17 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
Normal method is to just have one single patch, but it looks good oggie_rob.
comment:10 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
PositiveIntegerField as newforms.IntergerField with min_value