Lino Website

Documentation · Modules · adamo · Examples

query2.py

This example demonstrates that a Detail field in a Query returns another Query.

Source code:

# list of Belgian cities and number of inhabitants
from lino.apps.contacts.contacts_demo import startup
from lino.apps.contacts.contacts_tables import Nation

sess=startup()
be=sess.query(Nation).peek("be")
qry=be.cities("name inhabitants",orderBy="inhabitants")

qry.show(width=50)

print
print qry.getSqlSelect()

Output:

Cities (nation=Belgium)
=======================
name                                    |inhabitan
                                        |ts       
----------------------------------------+---------
Raeren                                  |9933     
Kelmis                                  |10175    
Eupen                                   |17872    
Verviers                                |52739    
Mons                                    |90992    
Brugge                                  |116848   
Liège                                   |185608   
Charleroi                               |200983   
Bruxelles                               |1004239  

SELECT nation_id, id, name, inhabitants FROM Cities WHERE nation_id = 'be' ORDER BY inhabitants

Copyright 2001-2007 Luc Saffre.
http://lino.saffre-rumma.ee
Generated 2007-06-07 16:23:39