On 3/15/06, Christopher Lenz <[EMAIL PROTECTED]> wrote: > I definitely agree that the model layer should do validation, as long > as that doesn't mean it's the *only* layer that does validation > (that's not how I understood the proposal, but some some of the > comments seemed to imply that). I may have forms that don't map 1:1 > to models; for those, parts of the validation must be done by the > formwrapper/manipulator, and other parts by the model classes.
The model layer certainly isn't the *only* layer that does validation. Of course, Django will continue to support custom forms and validation logic on a level that's decoupled from models. > There's a thin line here between convenient auto-conversion (e.g. > strings to numbers) and overloading the model class with logic that > simply doesn't belong there. In your web layer code, you have > something akin to a manipulator sitting between your model classes > and the view. The manipulator would be responsible for unmarshalling > POST parameters into a data structure that can be handled by the > model, including parsing stuff like dates and exploding "dotted" > parameters into nested dicts or whatever. Right -- that's exactly what will happen. > Example: the string representation of a date in may depend on the > locale of the remote user, which the model knows nothing about. The > conversion from string to datetime will need to happen in a layer > that is aware of the HTTP request context. (This is a somewhat > contrived example due to the abysmal state of international datetime > formatting/parsing in the Python standard library, but I'm sure there > are other examples). In this example, the view code would perform that logic -- not the model layer. The model layer is only responsible for *critical* validation logic that applies to *every instance of the model, ever* -- not special-cases. For special cases, you'll use a custom form/manipulator, just like before. Adrian -- Adrian Holovaty holovaty.com | djangoproject.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" 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-developers -~----------~----~----~----~------~----~------~--~---
