On Sun, Apr 26, 2009 at 3:32 PM, DolleDries <[email protected]> wrote:
> Given the model for web2py-wiki:
>
>
> db.define_table('tag',
>   db.Field('name'))
>
> db.tag.name.requires=IS_NOT_EMPTY()
>
> db.define_table('page',
>   db.Field('uuid',length=128,writable=False,default=str(uuid.uuid4
> ())),
>   db.Field('title'),
>   db.Field('menu',length=128),
>   db.Field('public','boolean',default=False),
>   db.Field('active','boolean',default=True),
>   db.Field('body','text'),
>   db.Field('tags','text'),
>   db.Field('created_by',db.auth_user,default=who,writable=False),
>   db.Field('created_on','datetime',default=now,writable=False))
>
> db.page.title.requires=IS_NOT_EMPTY()
> db.page.tags.requires=IS_IN_DB(db,'tag.id','%(name)s',multiple=True)
>
> Can somebody explain to to me what is meant by the last line???

IS_IN_DB() is a validator. It validates forms when you use SQLFORM()
or Crud (that uses SQLFORM). This line:

db.page.tags.requires=IS_IN_DB(db,'tag.id','%(name)s',multiple=True)

tells to web2py that field 'tags' in table 'pages' is only valid if
value inserted in exists in table 'tag' in field 'id'. It is a
one-to-many relationship. With IS_IN_DB() validator web2py knows that
it is a one-to-many and create a dropdown to select options. So, if
you create a SQLFORM using db.page, web2py will search db.tag table
and create a dropdown with db.tag rows insted of a input type=text in
space dedicated to field "tags".

The '%(name)s' tells to web2py to create a dropdown menu showing
'name' field of tag - it will verify if page.tags = tag.id, but will
show in dropdown tag.name.

But in this case we have multiple=True, so you can get more than one
tag to each page (so it is more than an one-to-many relationship).

> It seems to me this line has a diffenrent meaning: db.Field
> ('tags','text').
> I believe it should be somthing like: db.Field('tags', db.tag) or
> perhaps a SET or ENUM of tags...
>
> Put how is that produced dynamicly? Haven't found anything in the book
> or API yet..

-- 
 Álvaro Justen
 Peta5 - Telecomunicações e Software Livre
 21 3021-6001 / 9898-0141
 http://www.peta5.com.br/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to