Hi, folks: I appreciate the people who are willing to help out newbies here. In my journey up Django Mountain, I'm now at the stage where I want to validate data. My app is not interactive and has no web component; I'm just using Django as a database access layer.
My app reads some data out of files, and parse it into a Python classes of mine. Then I use those classes to populate two Django Model classes, which are subclasses of models.Model. If I make sure the incoming data is valid, then I can instantiate the Model classes, and call their .save() methods, and Django saves to the database successfully. So that much of the mechanism works. But in this messy world, not all the data I parse is valid. If some of the incoming strings are too long for my models.CharField() instances, then I get the following exception, which stops my script: _mysql_exceptions.Warning: Data truncated for column 'source' at row 1 What I would like to do is: 1. Have a clean way to write those errors to my log, instead of having the backend stop my script. Is there a pattern I can follow to catch these exceptions, write a sensible error message, and continue? 2. Use the Django model to help me validate the data. At the very least, I'd like to get at the maxlength parameters of the models.CharField() instances, and truncate overlong incoming strings appropriately (and write a message to my log). How can I get at these model parameters? An expression like "MyModel.mystringfield.maxlength" results in a "missing attribute" error. 3. Understand if the Django Modelform is the way I ought to be handling this. Forms are the only Django entity for which I can find documentation about doing validation in accordance with the Model. There's a lot in the Forms documentation about generating HTML and responding to request.POST. Are there any writeups or patterns of using Forms purely as a formatting and validation mechanism, with no HTML display or HTTP interaction? I'm reading through the Modelform documentation right now, but I'd love to know if I'm on the right track. Thanks in advance for any advice, or pointers to documentation I've overlooked! --Jim DeLaHunt, Vancouver, Canada http://jdlh.com/ (Happy Thanksgiving, you Canucks!) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

