On Wednesday, August 12, 2015 at 8:17:45 PM UTC-7, JC wrote:
>
> Hello,
> I´ve the following model:
>
> db.define_table('bsc_input',
>                 Field('id_p_indicator', db.p_indicator, label=T(
> 'Indicator'), notnull=True),
>                 Field('current_month', 'integer', label=T('Month'), 
> notnull=True),
>                 Field('current_year', 'integer', label=T('Year'), notnull=
> True),
>                 Field('current_value', 'float', label=T('Value'), notnull=
> True))  
>
>   and I want to setup a validation  so that I´m sure the combination of  '
> id_p_indicator', 'current_month' and 'current_year' are unique.
>
> How can I do it ?
>

I've done one custom validator; see
<URL:https://groups.google.com/d/msg/web2py/KC5BPC_xjv8/MeD88yDYtOcJ>
for the example.
 
I think I left out how I invoked that; my choice was to do it in a FORM:
  form = FORM('Activation code:',
              INPUT(_name='left', requires=[IS_NOT_EMPTY(), IS_HEXSTR()], 
_type="text", _maxlength="4", _class='activation', _id="left"),
 # more fields here 
 )



Another choice would be to use the onvalidation() method
<URL:http://web2py.com/books/default/chapter/29/07/forms-and-validators#onvalidation>
which I believe applies to the more sophisticated form helpers as well.

You could also use validate_and_insert() routine, but my understanding is 
that that is pretty much covered by the above techniques.
<URL:http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=before_#validate_and_insert--validate_and_update>

I'm not quite sure how you would enforce  that sort of validation at the 
SQL level or in the actual database.

/dps



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to