>
> On Thu, Dec 15, 2011 at 10:29 PM, Anthony <abas...@gmail.com> wrote:
>
>> Yes, in that case, your model is correct. I was confused because you said 
>> you want to "validate the existence of only 1 scale per group" -- yet there 
>> can be many scales per group. But from your example, it looks like maybe 
>> you're trying to ensure that the scale ranges for a given group do not 
>> overlap -- is that it?
>>  
>>
>
> Yes, that's my problem.
> Is there a way web2py can handle that validation?
> for example... if i have 2 scales:
>  - min_v : 0
>  - max_v : 10
>
>  - min_v : 21
>  - max_v : 30
>
> It shouldn't let me save the following 
>  -min_v : 8
>  -max_v : 24
>

You'll need a custom validator for that -- see 
http://web2py.com/book/default/chapter/07#Custom-Validators.

Your validator would have to do a query to get all the scales associated 
with the group id being validated, and then check to see if the new scale 
values overlap any of the existing scale ranges. At validation time, only 
the group id value will be passed to the validator, so you'll have to get 
the new scale values directly from request.vars.min_v and 
request.vars.max_v (assuming the values are being submitted via a form). 
See 
also http://web2py.com/book/default/chapter/07#Validators-with-Dependencies.

Another option is using an onvalidation function with your form, which will 
run after the usual validation process. 
See http://web2py.com/book/default/chapter/07#onvalidation. Actually, that 
may be a little more straightforward than writing a custom validator.

Anthony
 

Reply via email to