Skip to content

Instantly share code, notes, and snippets.

@mdipierro
Created September 26, 2020 17:38
Show Gist options
  • Save mdipierro/ffd127c83cf081daff73c7546d39bbe5 to your computer and use it in GitHub Desktop.
Save mdipierro/ffd127c83cf081daff73c7546d39bbe5 to your computer and use it in GitHub Desktop.
pydal reference examples
from pydal import DAL, Field
db=DAL()
db.define_table('person', Field('name'))
id = db.person.insert(name="Max")
print("%(name)s" % id)
db.define_table('dog', Field('name'), Field('owner', db.person))
db.dog.insert(name="Snoopy", owner=id)
dog = db(db.dog).select().first()
print("%(name)s" % dog.owner)
print(dog.owner.name)
@mdipierro
Copy link
Author

cache =	py4web.Cache()
def format_person(id):
    key	= "person-%s" %	id
    return cache(key, lambda id: (db.person._format % db.person[id])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment