| db.define_table('my_page',
Field('name', 'string', length=256, label=T('Name')),
Field('title', 'string', length=512, label=T('Title')),
Field('subtitle', 'string', length=512, label=T('Subtitle')),
Field('page_content', 'text', label=T('Page Content')),
Field('parent', 'reference my_page', label=T('Parent')),
Field('url_builder', unique=False,readable=True, writable=True, length=255, label=T('Url Builder')),
Field('url', unique=True, length=255, readable=True, writable=True, label=T('Url')),
Field('approved', 'boolean', default=True, label=T('Approved')),
format='%(name)s')
db.my_page.url_builder.compute = lambda r: str(r.name)+' '+str(r.title)
db.my_page.parent.requires = IS_EMPTY_OR(IS_IN_DB(db, db.my_page.id, ' %(name)s - %(title)s - ID %(parent)s',
orderby=db.my_page.parent))
db.my_page.url.compute = lambda row: IS_SLUG(keep_underscores=False)(row.url_builder)[0]
## Below code is needed only once.
if db(db.my_page.id > 0).count() == 0:
db.my_page.insert(
name = 'index',
title = 'index',
subtitle = 'index',
page_content = 'Lore ipsum lore ipsum Lore ipsum lore ipsum')
db.my_page.insert(
name = 'Second Page',
title = 'My home page',
subtitle = 'index',
page_content = 'Lore ipsum lore ipsum Lore ipsum lore ipsum')
|