#497 closed enhancement (invalid)
Request DB API access to the validation information in the model
Reported by: | anonymous | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the data model, there is validation information such as character field maximum length, which is used for form entry validation in the Admin interface.
However, this doesn't seem to be available from the DB API for validation:
e.g. Using the polls/choices example;
>>> from django.models.polls import polls, choices >>> p = polls.get_object(pk=1) >>> p.question = 'x'*300 >>> p.save() Traceback (most recent call last): ... ProgrammingError: ERROR: value too long for type character varying(200) UPDATE polls_polls SET question='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxK >>>
It would be nice to have something like:
>>> polls.is_data_valid_for_field(data='x'*300, field=question) False >>>
and/or
>>> polls.validation_data['question'] {'max_length':200, ... }
Perhaps this could be integrated with the Validators interface?
Change History (2)
comment:1 by , 19 years ago
Type: | defect → enhancement |
---|
comment:2 by , 19 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
This is what manipulators are for... Check out http://www.djangoproject.com/documentation/forms/
Note:
See TracTickets
for help on using tickets.
"which is used for form entry validation in the Admin interface"
(actually, it might not be - I was just assuming. After a quick dig through the DB backends, I don't quite see how it could be explicitly checked)