Arun,

this line:
persons_and_dogs = db((db.person.id==db.ownership.person) &

(db.dog.id==db.ownership.dog))
won't run on GAE because of the joins. You can choose to keep the data
structure as you have it and run 2 queries and mesh the results. before
the advent of list properties i was doing that. it kinda sucked.

Here's what i would try with your model: (note that i did not run this
code, so it might contain typos...)

Models
---------
db.define_table('dog',Field('name'))
db.define_table('person', Field('name'),
'dogs', 'list:reference dog')

this assumes that a person has many dogs, and not that dogs have many
people. if you prefer to think of it as dogs owning people i'd put the
person field on the dog table. (you know your cat owns you, so for cats
it would have to be that way)

given that model, once you create dog records, each dog will show as an
option in a multi-select list for the 'dogs' field on person. so use
CRUD or create your own controllers with the default form renderings as
in:

form = SQLFORM(db.person)

and put that in your view:

{{=form}}

to get the default inputs.

when you want to see dogs and people together in your view you would
select people:

rows = db(db.person.id>0).select()

and in the view:

{{for row in rows:}}
person: {{=row.person}} dogs:
{{for dog in row.dogs:}}
{{=dog.dog}}
{{pass}}
<br />
{{pass}}

note the trick that in web2py the list:reference field is a proper
web2py table reference and when you access the properties on the dog
reference it automatically runs the query and gives you the result.

hope this makes some sense!

christian

christian

Reply via email to