Making my first foray into web2py and wanted to run a few things by
the list.

Let's say I want to have a list of Libraries, each of which contains a
Collection of Books. Here's what I've got so far:

db.define_table('library',
    Field('id','id',
          represent=lambda id:SPAN(id,'
',A('view',_href=URL('library_read',args=id)))),
    Field('name', type='string', notnull=True,
          label=T('Name')),
    Field('address', type='string', notnull=True,
          label=T('Address')),
    format='%(name)s',
    migrate=settings.migrate)

db.define_table('book',
    Field('id','id',
          represent=lambda id:SPAN(id,'
',A('view',_href=URL('book_read',args=id)))),
    Field('title', type='string', notnull=True,
          label=T('Title')),
    Field('author', type='string', notnull=True,
          label=T('Author')),
    format='%(name)s',
    migrate=settings.migrate)

db.define_table('collection',
    Field('id','id',
          represent=lambda id:SPAN(id,'
',A('view',_href=URL('collection_read',args=id)))),
    Field('library_id', type='reference library',
          label=T('Library ID')),
    Field('book_id', type='reference book',
          label=T('Book ID')),
    format='%(name)s',
    migrate=settings.migrate)

Ultimately I would add other fields to the tables, stuff like a
checked_out boolean in Collections, or a rating in Books, etc.

Now, inserting and dealing with individual items is no problem (the
provided examples cover this fairly well.) Where I'm getting confused
is in how to make it a bit more user friendly. I'd like to be able to
have the Library creation form also allow Book entries. So, when
entering a new Library, you also have fields for the Books in that
Library's Collection. If the Book has already been entered pull it up
from autocomplete. Since there's also no set number of Books in a
collection, how would I keep adding additional Book entry fields to
the end of the form?

Any advice or pointers would be much appreciated.

thanx!

Reply via email to