On Mon, Aug 06, 2007 at 03:24:28PM -0500, Jim Steil wrote: > class RailCategory(SQLObject): > class sqlmeta: > style = Style(longID=True) > idName = 'railCategoryId' > > name = UnicodeCol(length=50) > description = UnicodeCol() > railCars = RelatedJoin("RailCar", intermediateTable="railCategoryCar", > joinColumn="railCategoryId", > otherColumn="railCarId") > > class RailCar(SQLObject): > class sqlmeta: > style = Style(longID=True) > idName = 'railCarId' > > carInitials = UnicodeCol(length=10) > carNumber = IntCol() > active = BoolCol(default=True) > createdOn = DateCol(default=datetime.now()) > railCategories = RelatedJoin("RailCategory", > intermediateTable="railCategoryCar", > joinColumn="railCarId", > otherColumn="railCategoryId") > > Now I want to get a list of rail cars in a category. However, I want > the rail cars sorted by the name of the rail car. > > Here is where I'm at: > > # Get the data and add it to the report > rcats = RailCategory.select(orderBy='name') > for rcat in rcats: > printName = rcat.name > for rc in rcat.railCars: > print rc.name
Solution N1, in Python: rcats = RailCategory.select(orderBy='name') for rcat in sorted(rcats, key=operator.attrgetter('name')): Solution N2, still in Python: class RailCategory(SQLObject): railCars = RelatedJoin("RailCar", intermediateTable="railCategoryCar", joinColumn="railCategoryId", otherColumn="railCarId", orderBy="name") Solution N3, in SQL: class RailCategory(SQLObject): railCars = SQLRelatedJoin("RailCar", intermediateTable="railCategoryCar", joinColumn="railCategoryId", otherColumn="railCarId", orderBy="name") Oleg. -- Oleg Broytmann http://phd.pp.ru/ [EMAIL PROTECTED] Programmers don't die, they just GOSUB without RETURN. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss