Opened 10 years ago

Closed 9 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:

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 Changed 10 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 9 years ago by adrian

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

This is what manipulators are for... Check out http://www.djangoproject.com/documentation/forms/

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