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*
rochacbr...@gmail.com | 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>

-- 



Reply via email to