#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 , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 14 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Then why does TextField accept a max_length parameter?
comment:3 by , 14 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
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 , 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.
Text fields have no maximum length -- that's the whole point of text fields. If you want length checking, use
CharField
.