class LESS_THAN
    def __init__(self,db,query,field,error_message='...'):
          self.db,self.query,self.field=db,query,field)
          self.error_message=error_message
    def __call__(self,value):
          try:
               value=inv(value)
               records=self.db(self.query).select(limitby=(0,1))
               if value<0 or value>=records[0][self.field]: raise
               return (value,None)
          except:
               return (value,self.error_message)

db.invoice_item.count.requires=IS_IN_DB
(db,db.ware.id==request.vars.id,'count')

On Jan 10, 5:28 am, Julius Minka <[email protected]> wrote:
> db.define_table('invoice_item',
>                 SQLField('invoice_nr',required=True),
>                 SQLField('ware',db.ware,required=True),
>                 SQLField('discount','double',required=True),
>                 SQLField('count','double',required=True))
> db.invoice_item.ware.requires=IS_IN_DB(db,'ware.id','%(artnr)s%(size)s')
>
> How to validate "count" field to be less or equal than db.ware.count in
> corresponding record of table db.ware based on choice made by
> invoice_item.ware?
> To tell it simply, in human words: how to not sell more items than I
> currently have?
>
> I saw some validation examples in archives using IS_EXPR or custom
> validators, but in those all relationships between fields stayed inside
> the same table.
>
> Julius
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to