Getting max_length for forms.IntegerField

3,208 views
Skip to first unread message

Camilo Nova

unread,
May 12, 2011, 7:45:22 PM5/12/11
to Django developers
Hi all,

Were im working we usually take in mind that fields in web forms
should have a max length value for input, and we apply them well in
cases like:

username = forms.CharField(
max_length=30,
)

But in cases like:

cash = forms.IntegerField(
min_value=0,
max_value=1000000,
)

Should it be good to set the max_length property too, even it will be
great if by defaults max_length value would be 'len(max_value)'

you see this usefull as me?

Russell Keith-Magee

unread,
May 12, 2011, 7:52:52 PM5/12/11
to django-d...@googlegroups.com

On a CharField, max_length is a basic structural consideration -- how
many characters can the field hold.

min/max value, however, isn't a structural consideration -- it's a
validation issue. Regardless of the min/max value, the database will
allocate "integer" storage.

What you're looking for is a way to validate that the field has a
value in a given range -- and Django already has those:

http://docs.djangoproject.com/en/dev/ref/validators/

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages