Maybe this could help :
http://web2py.com/books/default/chapter/29/14?search=dummy#Populating-database-with-dummy-data

On Wed, Jun 27, 2012 at 4:13 AM, Alec Taylor <[email protected]> wrote:

> Here's a simple test-case:
>
> # Models
> db.define_table(
>    'group_of_events',
>    Field('group_name', requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db,
> 'group_of_events.group_name')]),
>    Field('events', 'list:reference db.event', requires=[IS_IN_DB(db,
> 'event.id', '%(event_name)s [%(group_id)s]', multiple=True)]), #
> populate with: WHERE db.event.group_id == self.id
>    format='%(group_name)s'
> )
>
> db.define_table(
>    'event',
>    Field('event_name', requires=IS_NOT_EMPTY()),
>    Field('group_id', 'reference db.group_of_events'),
>    format='%(event_name)s'
> )
>
> # Controllers
> def index():
>    return dict(groups_list=SQLTABLE(db().select(db.group_of_events.ALL)))
>
> # Views
> {{if 'groups_list' in globals():}}
> {{=groups_list}}
> {{else:}}
> <h5>group_list not found :\</h5>
> {{pass}}
>
> # {{pass}}!
>
> How do I populate the group_of_events events field with events from
> the event table?
>
> Thanks for all suggestions,
>
> Alec Taylor
>
> --
>
>
>
>

-- 



Reply via email to