Your example works but with two corrections discussed below:
> mynewdb=SQLDB("sqlite://mynewdb.db")
> import datetime
>
> now = datetime.datetime.now()
>
> mynewdb.define_table('tag',
> mynewdb.Field('name'),
> mynewdb.Field('description', 'text'))
# remove
# mynewdb.Field('post_id', 'integer'))
# because posts have tags but a tag does not belong to a post
> mynewdb.define_table('posts',
> mynewdb.Field('title'),
> mynewdb.Field('body', 'text'),
> mynewdb.Field('author'),
> mynewdb.Field('tags'),
> mynewdb.Field('date_created', 'datetime', default=now),
> mynewdb.Field('draft', 'boolean', default='T'))
>
# removed
# mynewdb.tag.post_id.requires=IS_IN_DB(mynewdb, mynewdb.posts.id)
# becuase tag.post_id should not be there
> mynewdb.posts.title.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB
> (mynewdb,mynewdb.posts.title)]
> mynewdb.posts.body.requires=IS_NOT_EMPTY()
> mynewdb.posts.tags.requires=IS_IN_DB(mynewdb, mynewdb.tag.name, '% (name)s',
> multiple=True)
# This is it. If you have some records in the tag table
# the above line will render with a multiple select dropbox.
# You can select one or more of use jquery multiselect plugin
# to change the appearence
> mynewdb.posts.draft.requires=IS_NOT_EMPTY()
> mynewdb.posts.date_created.requires=IS_DATE('%d/%m/%y')
>
> mynewdb.define_table('comments',
> mynewdb.Field('post_id', 'integer', mynewdb.posts),
> mynewdb.Field('url', default=''),
> mynewdb.Field('email', default='[email protected]'),
> mynewdb.Field('author'),
> mynewdb.Field('date_created', 'date',default=now),
> mynewdb.Field('body', 'text'))
>
> mynewdb.comments.post_id.requires =
> IS_IN_DB(mynewdb,mynewdb.posts.id,'%(title)s')
> mynewdb.comments.author.requires = IS_NOT_EMPTY()
> mynewdb.comments.body.requires = IS_NOT_EMPTY()
> mynewdb.comments.email.requires = IS_EMAIL(error_message="Please provide a
> valid email address")
> mynewdb.comments.date_created.requires=IS_DATE('%d/%m/%y')
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---