Hi thanks a lot for the help, i put this code in my model, and it runs
fine.

inventory=db().select(db.Inventory.ALL)
for i in inventory:
    if db((i.idProducto==db.Inventory.idProduct)&
(i.idCountry==db.Inventory.idCountry)).count()>1:
        db(db.Inventory.id == i.id).delete()

However I'd like to learn how modify the class becouse i think is the
best way to do it. I can't understand the code a lot. So please,
how do i edit this code for settings the id of the current record you
can prevent the check on update?

    def set_self_id(self, id):
        self.record_id = id


On 27 nov, 01:41, mdipierro <mdipie...@cs.depaul.edu> wrote:
> Look into gluon.validators.IS_NOT_IN_DB
>
> specifically:
>
>     def set_self_id(self, id):
>         self.record_id = id
>
> By settings the id of the current record you can prevent the check on
> update.
>
> Massimo
>
> On Nov 26, 4:32 pm, __Kyo__ <iacastil...@gmail.com> wrote:
>
>
>
> > Hi, i use this code in my application, it works very good when i
> > insert a new record, but i have a little problem when i want to update
> > a registry. For example:
>
> > I have un my table inventory: product, country, quantity
>
> > If i insert pencil, canada, 40 it inserts fine
>
> > then if i want to insert again pencil, canada, 50 it doesnt insert
> > beacuse i already have pencils in canada. This is working fine.
>
> > My problem is here, in the update. For example
>
> > I want to update my number of pencils in Canada, beacause i buy
> > another 50 pencils. I put update
> > pencil, canada, 90
>
> > But it says it already have pencils in canada, its like i am inserting
> > a new registry and not doing an update. How can i solve this?
>
> > This is my validator, is in the model:
>
> > class IS_NOT_IN_DB_DDOWN_UIM(IS_IN_DB):
> >     def __init__(self,*a,**b):
> >         IS_IN_DB.__init__(self,*a,**b)
> >     def __call__(self,value):
> >         e=IS_IN_DB.__call__(self,value)
> >         if e[1]:return e             e=IS_NOT_IN_DB(db
> > (db.Inventory.idProduct==request.vars.idProduct),'Inventory.idCountry',erro­r_message=self.error_message)
> > (value)
> >         return e
>
> > db.Inventory.idCountry.requires=IS_NOT_IN_DB_DDOWN_UIM
> > (db,'Country.id','%(nCountry)s',error_message="The product is already
> > in this country.")- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -

--

You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to