Tried Denes's suggestion, and resulrs are perect! Thanks Denes!

did this:

        id=db.local_user.insert(dateTime=datetime.now())
        rec=db(db.local_user.id==id)
        for key,value in localUserDict.items():
            if key in db.local_user.fields:rec.update(**{key:value})
        db.commit()

The filter option seems like a good thing as well, i will try that one
next!

Thanks for the help!

Mart :)



On Jul 11, 3:58 pm, mart <msenecal...@gmail.com> wrote:
> Will this day ever end!? ;)
>
> Thanks David, will have a look at that too! :)
>
> Thanks,
> Mart :)
>
> On Jul 11, 10:50 am, "David J." <da...@styleflare.com> wrote:
>
>
>
>
>
>
>
> > You may want to look at the _filter_fields
>
> > Look at web2py slices; this way you can pass a dict and it updates with
> > the relevant fields/
>
> > On 7/11/11 10:38 AM, mart wrote:
>
> > > Hi Denes,
>
> > > Thanks for the great explanation! now, its making sense to me!!
>
> > > I'll apply the changes below
>
> > > Thanks :)
> > > Mart :)
>
> > > On Jul 11, 9:34 am, DenesL<denes1...@yahoo.ca>  wrote:
> > >> Hi Mart,
>
> > >> to be able to use the key in the update you have to pass it in a dict.
> > >> I would do:
>
> > >> id=db.local_user.insert(dateTime=datetime.now())
> > >> # you seem to be updating one rec only
> > >> rec = db(db.local_user.id==id)
> > >> for key,value in localUserDict.items():
> > >>    if key in db.local_user.fields:
> > >>      rec.update(**{key:value})
> > >> db.commit() # after all updates are in
>
> > >> or using a comprehension:
>
> > >> id=db.local_user.insert(dateTime=datetime.now())
> > >> # you seem to be updating one rec only
> > >> rec = db(db.local_user.id==id)
> > >> [rec.update(**{key:value}) for key,value in localUserDict.items() if
> > >> key in db.local_user.fields]
> > >> db.commit() # after all updates are in
>
> > >> Denes.
>
> > >> On Jul 10, 11:55 pm, mart<msenecal...@gmail.com>  wrote:
>
> > >>> Hi,
> > >>> shouldn't something lik this work? or maybe i'm missing something for
> > >>> passing in a variable for a field name?
> > >>>          id=db.local_user.insert(dateTime=datetime.now())
> > >>>          for key in localUserDict.keys():
> > >>>              for field in db.local_user.fields:
> > >>>                  if field==key:
> > >>> db(db.local_user.id==id).update(field=localUserDict[key])
> > >>>                      db.commit()
> > >>> the exception is of course that the Field field does not belong to the
> > >>> local_user table
> > >>> Thanks,
> > >>> Mart :)

Reply via email to