Lino Website

Documentation · Modules · adamo · Examples

pizzeria3.py

This example demonstrates a report with joined tables.

Source code:

from lino.apps.pizzeria.pizzeria import Product, OrderLine
from lino.apps.pizzeria.services import \
     MyPizzeria, populate

app = MyPizzeria()
dbc = app.createContext()
populate(dbc)

p=dbc.query(Product).peek(1)

qry = dbc.query(OrderLine,"order.date order.customer",
                 product=p)
qry.show(
    columnWidths="10 13",
    title="Who bought %s (product# %s)?" % (p.name, p.id))

print
print qry.getSqlSelect()

del qry, dbc, app

Output:

Who bought Pizza Margerita (product# 1)?
========================================
order.date|order.custome
          |r            
----------+-------------
2003-08-16|Henri        
2003-08-16|James        
2004-03-18|Bernard      
2004-03-19|Henri        

SELECT lead.id, lead.order_id, xorder.id, xorder.xdate, xorder.customer_id, lead.productProducts_id, lead.productServices_id FROM OrderLines AS lead LEFT JOIN Orders AS xorder ON (lead.order_id = xorder.id) WHERE productProducts_id = 1 AND productServices_id ISNULL

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