I'm using something similar to prefab queries on other objects as if
they were views
I need to show a list of orders (cotta) by dept/customer
(reparto,cliente) filtered by approval date (data_lancio)
in order to print some special labels
First I get only relevant info from the main orders table (data names
ending by _id are foreign keys to other tables)
selCot = sqa.select([
tabCot.c.id.label("cotta"),
tabCot.c.impianti_id.label("reparto"),
tabCot.c.anagrafiche_id.label("cliente"),
tabCot.c.data_lancio.label("lancio"),
],
).alias("etichette_per_cotta")
Then I build a list of customers including number of lots approved in
the date range
selCli = sqa.select([
selCot.c.reparto.label("reparto"),
selCot.c.cliente.label("cliente"),
sqa.func.count(selCot.c.cotta).label("num_cotte"),
sqa.func.min(selCot.c.lancio).label("min_lancio"),
sqa.func.max(selCot.c.lancio).label("max_lancio"),
],
sqa.and_(
selCot.c.reparto==sqa.bindparam("reparto"),
selCot.c.lancio.between(sqa.bindparam("da"), sqa.bindparam
("a"))
),
group_by=[selCot.c.reparto, selCot.c.cliente],
).alias("etichette_per_cliente")
Then I MAP the selCli query to some object
mapper(EtichetteCliente, selCli, primary_key=[selCli.c.reparto,
selCli.c.cliente,],[SNIP])
[SNIP] includes orm.relation(s) to connect customer description and
other data
Finally when I build the list I callect all parameters and query
objects like this:
customers = sorted(EtichetteCliente.query.params({"reparto":
reparto.id, "da": dataDa, "a": dataA}).all())
Hope it helps
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.