Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#497 closed enhancement (invalid)

Request DB API access to the validation information in the model

Reported by: anonymous Owned by: adrian
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: UI/UX:


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?

Attachments (0)

Change History (2)

comment:1 Changed 9 years ago by anonymous

  • Type changed from defect to enhancement

"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 8 years ago by adrian

  • Resolution set to invalid
  • Status changed from new to closed

This is what manipulators are for... Check out

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.