Lino Website

Documentation · Modules · adamo · Examples

filters2.py

This example shows how to set a search filter and the depth=1 argument on a detail column.

Source code:

from lino.apps.contacts.contacts_demo import startup
from lino.apps.contacts.contacts_tables import Nation
from lino.adamo.filters import NotEmpty

dbc = startup(big=True)
        
qry=dbc.query(Nation,"id name")
qry.addColumn("cities",search="dre",orderBy="name",depth=1)
qry.addColFilter('cities',NotEmpty)
qry.show(
    columnWidths="2 15 *",
    title="Nations and their Cities containing search string 'dre'")

print
print qry.getSqlSelect()

del dbc, qry

Output:

Nations and their Cities containing search string 'dre'
=======================================================
id|name           |cities                                  
--+---------------+----------------------------------------
be|Belgium        |Audregnies (be), Berendrecht (be),      
  |               |Drehance (be), Gondregnies (be),        
  |               |Houdremont (be), Jandrain-Jandrenouille 
  |               |(be), Kieldrecht (be), Merendree (be),  
  |               |Mont-Saint-Andre (be), Saint-Andre (be),
  |               |Wandre (be), Warnant-Dreye (be), Waudrez
  |               |(be), Xhendremael (be), Zwijndrecht (be)
de|Germany        |Drebkau (de), Dreieich (de),            
  |               |Drensteinfurt (de), Dresden (de), Sankt 
  |               |Andreasberg, Bergstadt (de)             

SELECT id, name_en FROM Nations WHERE EXISTS (SELECT * FROM Cities WHERE nation_id=Nations.id AND name LIKE '%dre%' OR zipCode LIKE '%dre%' ORDER BY name)

Refering articles:

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