A little correction for any future visitor:

compute= lambda row: "%(username)s-%(songname)s-%(playlist_name)s"),
should be:
compute= lambda row: "%(username)s-%(songname)s-%(playlist_name)s" %row),

Anyway the solution is great. Thanks a lot.

El miércoles, 12 de septiembre de 2012 00:54:45 UTC+2, rochacbruno escribió:
>
> db.define_table('likes',
>     Field('username', 'reference auth_user'),
>
>     Field('songname', 'reference songs'),
>     Field('playlist_name', 'reference playlist'),
>     Field('unique_key', unique=True, notnull=True,  compute= lambda row: 
> "%(username)s-%(songname)s-%(playlist_name)s"),
>      
> )
>
> Now on any attempt to insert duplicates DAL will have an exception, 
> because unique_key is unique and the computation will try to add same 
> values.
>
> try:
>     db.likes.insert(......)
> except:
>     #YOU ALREADY LIKE THIS
>
>
> *Bruno Cezar Rocha** - @rochacbruno*
> rocha...@gmail.com <javascript:> | Mobile: +55 (11) 99210-8821
> www.CursoDePython.com.br | www.rochacbruno.com.br
> Blog: Using Python to get all the external links from a 
> webpage<http://rochacbruno.com.br/using-python-to-get-all-the-external-links-from-a-webpage/>
>   Get a signature like this. 
> <http://r1.wisestamp.com/r/landing?promo=18&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_18>
>  Click 
> here.<http://r1.wisestamp.com/r/landing?promo=18&dest=http%3A%2F%2Fwww.wisestamp.com%2Femail-install%3Futm_source%3Dextension%26utm_medium%3Demail%26utm_campaign%3Dpromo_18>
>    
>
>
>
>

-- 

--- 
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/groups/opt_out.


Reply via email to