Thanks for this. BTW, what did you use to make those screenshots? That's kind of cool.
On Oct 3, 12:32 pm, Yarko Tymciurak <yark...@gmail.com> wrote: > On Sat, Oct 3, 2009 at 9:42 AM, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > db(db.person.name=='Bob')(db.person.position==db.position.id).select > > (orderby=db.position.sort_order) > > Well - at least you had 10 hours to contemplate the solution before it was > handed to you. > > Here's an example of how testing it looks. > > New test app - "innerjoin"; > Preload some data thru admin app. > > yarko:~/workspace/web2py/devel$ python web2py.py -S innerjoin -M > default applications appear to be installed already > web2py Enterprise Web Framework > Created by Massimo Di Pierro, Copyright 2007-2009 > Version 1.67.2 (2009-10-02 21:17:51) > Database drivers available: SQLite3, MySQL, PostgreSQL > Starting cron... > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > Type "copyright", "credits" or "license" for more information. > > IPython 0.9.1 -- An enhanced Interactive Python. > ? -> Introduction and overview of IPython's features. > %quickref -> Quick reference. > help -> Python's own help system. > object? -> Details about 'object'. ?object also works, ?? prints more. > > In [1]: r=db(db.person.name=='Bob')(db.person.position==db.position.id > ).select(orderby=db.position.sort_order) > > In [2]: len(r) > Out[2]: 2 > > In [3]: for x in r: > ...: print x > ...: > <DALStorage {'person': <DALStorage {'update_record': <function <lambda> at > 0x9a194fc>, 'position': 1, 'id': 1, 'name': 'Bob'}>, 'position': <DALStorage > {'update_record': <function <lambda> at 0x9a195dc>, 'person': <gluon.sql.Set > object at 0x9a2086c>, 'sort_order': 1, 'id': 1, 'name': 'Manager'}>}> > <DALStorage {'person': <DALStorage {'update_record': <function <lambda> at > 0x9a19e2c>, 'position': 2, 'id': 2, 'name': 'Bob'}>, 'position': <DALStorage > {'update_record': <function <lambda> at 0x9a1964c>, 'person': <gluon.sql.Set > object at 0x9a2088c>, 'sort_order': 2, 'id': 2, 'name': 'worker'}>}> > > In [4]: > > On Oct 2, 9:39 pm, BioNip <bionic.nip...@gmail.com> wrote: > > > > Consider this code: > > > > > db.define_table('position', > > > > Field('name'), > > > > Field('sort_order', 'integer'), > > > > ) > > > > > db.define_table('person', > > > > Field('name'), > > > > Field('position', db.position), > > > > ) > > > > > #This sorts by the position.id > > > > db(db.person.name=='Bob').select(orderby=db.person.position) > > > > > #This fails. > > > > db(db.person.name > > =='Bob').select(orderby=db.person.position.sort_order) > > > > I want a list of people, ordered by their position.sort_order, not > > > position.id . Does anyone know how this can be accomplished? > > > > Thanks. > > > > -nip > > > > person_dat.png > 100KViewDownload > > position_dat.png > 111KViewDownload --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---