Django

Code

Ticket #4415 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

PositiveIntegerField in models.py does not get validation in form_for_model

Reported by: django@willhardy.net Assigned to: oggie_rob
Milestone: Component: Forms
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

positiveintegerfield.diff (0.6 kB) - added by django@willhardy.net on 05/29/07 06:01:35.
PositiveIntegerField? as newforms.IntergerField? with min_value
positiveintegerfield2.diff (0.9 kB) - added by django@willhardy.net on 05/29/07 06:03:39.
new class: newforms.PositiveIntegerField?
positiveintegerfield2.2.diff (0.9 kB) - added by Will Hardy <will@willhardy.net> on 05/29/07 06:28:48.
new class: newforms.PositiveIntegerField?
4415_fields.diff (1.0 kB) - added by oggie_rob on 09/14/07 15:27:07.
formfield method changes to PositiveIntegerField? and PositiveSmallIntegerField?
4415_tests.diff (1.0 kB) - added by oggie_rob on 09/14/07 15:28:03.
Test of positive integer values via form_for_model. Used generic "boundary" model which can be extended.

Change History

05/29/07 06:01:35 changed by django@willhardy.net

  • attachment positiveintegerfield.diff added.

PositiveIntegerField? as newforms.IntergerField? with min_value

05/29/07 06:03:39 changed by django@willhardy.net

  • attachment positiveintegerfield2.diff added.

new class: newforms.PositiveIntegerField?

(follow-up: ↓ 3 ) 05/29/07 06:07:07 changed by mtredinnick

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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.

05/29/07 06:28:48 changed by Will Hardy <will@willhardy.net>

  • attachment positiveintegerfield2.2.diff added.

new class: newforms.PositiveIntegerField?

(in reply to: ↑ description ) 05/29/07 06:29:51 changed by Will Hardy <will@willhardy.net>

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

(in reply to: ↑ 1 ) 05/29/07 06:35:36 changed by Will Hardy <will@willhardy.net>

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.

05/29/07 06:38:51 changed by django@willhardy.net

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

09/14/07 13:04:14 changed by anonymous

  • owner changed from nobody to anonymous.
  • status changed from new to assigned.

09/14/07 13:04:50 changed by oggie_rob

  • owner changed from anonymous to oggie_rob.
  • status changed from assigned to new.

09/14/07 15:27:07 changed by oggie_rob

  • attachment 4415_fields.diff added.

formfield method changes to PositiveIntegerField? and PositiveSmallIntegerField?

09/14/07 15:28:03 changed 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.

09/14/07 15:33:30 changed by oggie_rob

  • status changed from new to 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.

09/14/07 15:35:24 changed by oggie_rob

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

09/14/07 16:10:53 changed by SmileyChris

  • stage changed from Unreviewed to Ready for checkin.

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

09/14/07 21:37:07 changed by russellm

  • status changed from assigned to closed.
  • resolution set to fixed.

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


Add/Change #4415 (PositiveIntegerField in models.py does not get validation in form_for_model)




Change Properties
Action