Before we do this, I suggest you install plugin_wiki and do

db.define_table('lists', Field('name'))

def create_list():
    return dict(form=crud.create(db.lists))

def edit_list():
    mylist=db.lists(request.args(0)) or redirect(URL('create_list'))
    return dict(items=plugin_wiki.widget('tags',db.lists,mylist.id))

Instead of

   db.define_table('list_items', Field('list',db.lists),
Field('name'))

Plugin_wiki defines for you a many to many:

db.define_table('plugin_wiki_tag',
 
Field('name',requires=IS_NOT_IN_DB(db,'plugin_wiki_tag.name')),
                Field('links','integer',default=0,writable=False),
 
Field('created_by',db.auth_user,writable=False,readable=False,
                      default=auth.user_id),
                Field('created_on','datetime',
 
default=request.now,writable=False,readable=False),
                format='%(name)s', migrate=plugin_wiki_migrate)
db.define_table('plugin_wiki_link',
                Field('tag',db.plugin_wiki_tag),
                Field('table_name'),
                Field('record_id','integer'), migrate=plugin_wiki_migrate)

Then you can move code into your app, rename the tables and actions,
delete plugin_wiki, and you get what you want.



On Sep 17, 5:13 am, Omri <[email protected]> wrote:
> Hello,
>
> I'm writing a relatively big database application. A small part of it
> requires me to handle lists of values, where every list can only exist
> once, and where each item in the list can only exist once (but
> different lists can have items named the same way).
> A simplified model is:
>
> db.define_table('lists', Field('name'))
> and
> db.define_table('list_items', Field('list',db.lists), Field('name')).
>
> (there exists more fields but they are irrelevant to the current
> case).
>
> I am now writing an interface to define new lists. I would like to use
> SQLFORM to generate the forms required. I would like to use the
> validators IS_NOT_EMPTY() and IS_NOT_IN_DB() to make sure there will
> not exist two lists with the same name. The problem is that I would
> also like to make a similar validation on the items of the list, but
> to restrict the IS_NOT_IN_DB() to a set containing the list items.
>
> In the book it gives an example using SQLFORM.factory() on how this
> should be done, but when I simply use SQLFORM(db.list_items) I don't
> know how to access the different fields to add a requires validator in
> the action.
>
> I've tried looking in the book and the group but was unable to find a
> way to do so.
>
> Thanks,
> Omri Har-Shemesh

Reply via email to