Django model data consistency

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2011-01-31T05:37:45Z Indexed on 2011/01/31 7:26 UTC
Read the original article Hit count: 118

Filed under:
|

When creating a form, you can define a bunch of methods, clean_xyz, to make sure the data gets forced into the correct format. Is there any way to do this on a model level?

Perhaps I can override the field setters somehow? I want it so that if I write something like

my_address.postal_code = 'a1b2c3'

It will automatically get formatted into A1B 2C3. Perhaps throw an exception if it can't be converted. That way I know I'll never have any malformed data in the database.

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models