I'm trying to create a sortable, paginated DataGrid using SQLObjects
that use ForeignKeys, and not getting very far.
I have the following SQLObjects:
class Company(SQLObject):
name = UnicodeCol(alternateID=True)
divisions = MultipleJoin('Division')
class Division(SQLObject):
name = UnicodeCol()
company = ForeignKey('Company')
people = MultipleJoin('Person')
class Person(SQLObject):
first_name = UnicodeCol()
last_name = UnicodeCol()
division = ForeignKey('Division')
I then have the following method under my Root:
@pagiate("people", limit=50, default_order='last_name')
def People(self):
people=Person.select(orderBy='last_name')
people_widget = widgets.PaginateDataGrid(fields=[
widgets.PaginateDataGrid.Column('first_name', 'first_name',
'First Name', options=dict(sortable=True)),
widgets.PaginateDataGrid.Column('last_name', 'last_name',
'Last Name', options=dict(sortable=True)),
widgets.PaginateDataGrid.Column('company', lambda
row:row.division.company.name, 'Company',
options=dict(sortable=True)),
widgets.PaginateDataGrid.Column('division', lambda
row:row.division.name, 'Division', options=dict(sortable=True))
])
return dict(people_widget=people_widget)
This works, until I try to sort on the company or division fields,
unsurprisingly. Instinct tells me I don't need the lambdas, I should
be able to just use 'division.company.name' and 'division.name', since
from a tg-admin shell I can do:
p = Person.get(1)
print p.division.company.name
But instead I get:
AttributeError: 'Person' object has no attribute
'division.company.name'
Am I doing something wrong, or am I asking for the impossible?
Thanks,
Caleb Shay
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---