I have got the following master-detail construction:
A clubs controller containing the byplace function:
def byplace():
clubs=db((db.bedrijf.id==db.adres.bedrijf)&(db.bedrijf.id==db.bedrijfbranche.bedrijf)&(db.adres.plaatsnaam==request.vars.plaatsnaam)&(db.adres.adressoort==1)&(db.bedrijfbranche.branche==1)).select(db.bedrijf.id,db.bedrijf.bedrijfsnaam,db.bedrijf.ranking,db.adres.straatnaam,db.bedrijfbranche.branche,orderby=db.bedrijf.ranking|
db.bedrijf.bedrijfsnaam)
return dict(clubs=clubs)
displaying in the following view:
<table>
<tr>
<th>bedrijfsnaam</th>
<th>straatnaam</th>
</tr>
{{for club in clubs:}}
<tr>
<td>{{=A(club.bedrijf.bedrijfsnaam,_href=URL(r=request,f='clubdetails?
id=%s'%club.bedrijf.id))}}</td>
<td>{{=club.adres.straatnaam}}</td>
</tr>
{{pass}}
</table>
And in the clubs controller the clubdetails function:
def clubdetails():
id=request.vars.id
clubs=db(db.bedrijf.id==id).select()
addresses=db((db.adres.bedrijf==id)&(db.adres.adressoort==1))
communication=db(db.bedrijfcommunicatiemiddel.bedrijf==id)
if not len(clubs) and not len(addresses) and not
len(communication): redirect(URL(r=request,f='byplace'))
return
dict(club=clubs[0],address=addresses[0],communication=communication)
Clicking a link in the master view results in the following error:
Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py",
line 62, in restricted
exec ccode in environment
File "/Library/Python/2.5/site-packages/web2py/applications/b2c/
controllers/clubs.py", line 40, in <module>
File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py",
line 55, in <lambda>
self._caller=lambda f: f()
File "/Library/Python/2.5/site-packages/web2py/applications/b2c/
controllers/clubs.py", line 38, in clubdetails
return
dict(club=clubs[0],address=addresses[0],communication=communication)
TypeError: 'SQLSet' object is unindexable
In my model I got a table company, which contains the company name and
chamber of commerce number etc. (club=clubs[0]). Since a company can
have more than one address I got a separate address table, in the
details view, only the business address should be displayed
(address=addresses[0]). I also got a separate table for a company's
telephone number, fax number, e-mail address and web address. In the
details view all these numbers and addresses should be displayed,
hence (communication=communication).
Since the clubs=db(db.bedrijf.id==id).select() and
addresses=db((db.adres.bedrijf==id)&(db.adres.adressoort==1)) both
return one record I am not sure the return should read return
dict(club=clubs[0],address=addresses[0],communication=communication).
I suppose return
dict(club=clubs,address=addresses,communication=communication) will
have the same outcome.
Does one of you know what causes the TypeError: SQLSet object is
unindexable?
Best regards,
Annet.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---