-
Notifications
You must be signed in to change notification settings - Fork 8
Validation function at model field definition #9
Comments
And I prefer this to be agnostic even if it will not solve all the cases. Exemple 1:
Exemple 2:
If age is not valid it returns a 400 type response:
|
I'm wondering if we shouldn't just use Javascript schema here, I've heard that it's not too complicated to parse; I don't know if that's the same story for its generation |
@AntoineCezar The two examples you gave are already covered by either RangeField or EnumField. With validation functions I had something more elaborate, even something like cross fields validation ! @ametaireau Do you mean JSON schema ? |
yep, json schema. |
Parsed and executed in python, or JS executed server-side with http://code.google.com/p/pyv8/ |
Json Schema good parts:
|
Seems interesting indeed, but it looks like a different story : "replacing current formalism for model definitions by JSON schema". BTW, transforming current JSON to Backbone forms is currently done like this: Nothing extra is required for models. Except we want to have stuff like derived types (colour stored in string field) : |
The title is "Validation function at model field definition" not "custom validation logic between fields". So It contains the problem and the solution. Renaming may be necessary. I'd like to avoid a language specific solution, but if there no other way let's do it in JavaScript. |
Completely agree with what's being said here. Regarding the original issue, adding custom validation between fields at model definition level is probably a bad idea. @AntoineCezar pointed this out with the "password confirmation" example (two fields in form, validated together, but not relevant in the model itself). BTW Chris Mcdonough said decoupling models from forms was a good idea :) http://pyvideo.org/video/1407/about-django-from-the-pyramid-guy This custom validation between fields may then be left to client-side. |
Allow users to define their own validation function in the posted JSON model definition :
Most appropriate language seems to be Javascript (since JSON).
Javascript syntax must be checked during model definition.
Validation function should be executed on model post. In my opinion, server side (thus in python) :
http://renesd.blogspot.fr/search/label/shitjs
https://bitbucket.org/pypy/lang-js/src/de89ec32a7dc/js/javascript-interpreter.txt
http://code.google.com/p/pyv8/ : extra dep :(
The text was updated successfully, but these errors were encountered: