> class Resource(SQLObject):
> name = UnicodeCol(alternateID=True, length=30)
> completionTime = DateTimeCol()
>
> class Location(SQLObject):
> name = UnicodeCol(alternateID=True, length=256)
> lat = DecimalCol(size=9, precision=6)
> lon = DecimalCol(size=9, precision=6)
> res_id = ForeignKey('Resource')
> ...
> I am tempted to write some code like this in controllers.py (but it
> looks sucky to me, so I know it MUST be wrong :-)
> class Root(controllers.RootController):
> "..."
> @expose()
> @expose("json")
> def resourcelist(self):
> resultSet = []
> resourceList = [[resource.id, resource.name,
> resource.completionTime]
> for resource in Resource.select(orderBy=Resource.q.name)]
> for r in resourceList:
> res_id = r[0]
> locs = [[loc.name, loc.lat, loc.lon] for loc in
> Location.select(Location.q.id==res_id)]
> for l in locs:
> resultSet.append([r[1],l[0], str(l[1]), str(l[2]), r[2] ])
> return dict(resources=resultSet)
>
> What's the sporty way to do this (or is the answer to add attributes
> to the model?
> Thanks. I love this group BTW
> Dana
why are you fetching all the data in this place?
you can as well pass a SelectResults object to the template...
everything will be figured out automatically!
example:
-----model.py-----
class Resource(SQLObject):
name = UnicodeCol(alternateID=True, length=30)
completionTime = DateTimeCol()
locations = MultipleJoin("Location")
class Location(SQLObject):
name = UnicodeCol(alternateID=True, length=256)
lat = DecimalCol(size=9, precision=6)
lon = DecimalCol(size=9, precision=6)
res_id = ForeignKey('Resource')
-----controllers.py ------
return dict(resources = Resource.select().orderBy(Resource.q.name))
------template.kid------
<div py:for="resource in resources">
<span py:replace="resource.name">resourcename</span>
<ul>
<li py:for="l in resource.locations"
py:content="l.name">locationname</li>
</ul>
</div>
hope it helps!
Frank
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---