Getting more comfortable with Web2Py and there sure is a lot to like about
it.

I'm wondering what is considered best practice for inserting records that
might already exist, when I also want to get the id of the record if it does
exist.  I haven't come across a shortcut for this.

For now, I'm using a try statement, as below, for a table that stores web
page data:

try:
     urlID = db.web_page(url=url).id
except:
     urlID = db.web_page.insert(url=url)

I notice that early last year there was a discussion of how to create the
equivalent of Django's get_or_create(), which does this.  I don't see that
that even made its way into Web2Py.

NIck

Reply via email to