Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#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


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
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)


>>> polls.validation_data['question']
{'max_length':200, ... }

Perhaps this could be integrated with the Validators interface?

Change History (2)

comment:1 Changed 14 years ago by anonymous

Type: defectenhancement

"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)

comment:2 Changed 14 years ago by Adrian Holovaty

Resolution: invalid
Status: newclosed

This is what manipulators are for... Check out

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