Opened 16 years ago

Closed 14 years ago

Last modified 11 years ago

#8263 closed Uncategorized (invalid)

models.TextField max_length

Reported by: sanha Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: TextField, max_length
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

if some model has file type of models.CharField.

When field string was overflow max_length, ProgramError was raised.

But, if model has field type of models.TextField in same case.

Nothing was raised.

In this case, max_length seems to be a useless thing.

Change History (4)

comment:1 by Jacob, 16 years ago

Resolution: invalid
Status: newclosed

Text fields have no maximum length -- that's the whole point of text fields. If you want length checking, use CharField.

comment:2 by anonymous, 14 years ago

Resolution: invalid
Status: closedreopened

Then why does TextField accept a max_length parameter?

comment:3 by Gabriel Hurley, 14 years ago

Resolution: invalid
Status: reopenedclosed

You can pass max_length as a keyword argument to any model field that inherits from Field; that doesn't mean that the class actually does anything with it. Nowhere that I see in the docs or code indicate that it will work.

comment:4 by vkstoykov@…, 11 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

Everybody that has database knowledge knows that in database TextFields are not restricted by length, but django Models are used to define domain logic in your application like in MVC pattern. I know that Django tells us that it does not follow MVC instead it follows MTV but M in MVC and M in MTV is the same thing.

In Django there is a fields that has programmatically defined restrictions like URLField and EmailField. Also for django model fields is possible to define validators, which are also programmatically restrictions. This is domain logic of the application. In the database I can put not valid URLs and not valid E-Mail addresses or values that will not pass django validators. These fields are created for easy validation in forms.

If user want to use TextField (because of default widget) it will not harm if TextField accept max_length argument and this argument is used for form validation. And by this simple thing also the DRY principle will be followed when someone wants field that will look as Textarea but will have restricted length.

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