On Sunday, June 21, 2015 at 9:13:03 AM UTC-7, Mario Blataric wrote:
>
> Hi,
>
It's awfully hard for me to read black on black, so I may be
misunderstanding what you are trying.
>
> I have following table definition:
>
> b.define_table('exchange_rate',
> Field('currency', length=5, required=True, notnull=True,
> label='Valuta'),
> Field('rate_date', type='date', required=True, notnull=True,
> label='Datum tečaja'),
> Field('buy_rate', type='decimal(18,6)', required=True,
> notnull=True, label='Kupovni tečaj'),
> Field('median_rate', type='decimal(18,6)', required=True,
> notnull=True, label='Srednji tečaj'),
> Field('sell_rate', type='decimal(18,6)', required=True,
> notnull=True, label='Prodajni tečaj'))
>
>
> What I want is to produce "yyyy-mm" field from rate_date and then group
> data by that field.
>
> My query should be like this (a non working example, but to give you an
> idea what I need):
>
> exchangeData = db().select(
> db.exchange_rate.currency,
> str(db.exchange_rate.rate_date.year()) + "-" +
> str(db.exchange_rate.rate_date.month()),
> db.exchange_rate.kupovni_tecaj.avg().with_alias('buy_rate_avg'),
> db.exchange_rate.prodajni_tecaj.avg().with_alias('sell_rate_avg'),
> orderby=db.exchange_rate.valuta|db.tecajna_lista.datum_tecaja,
>
> groupby=db.exchange_rate.valuta|db.tecajna_lista.db.exchange_rate.rate_date.year()|db.exchange_rate.rate_date.month())
>
>
>
If you are trying to "print" the year and month from a selected row, (and
use them for sorting), don't you have to select the row, and then put your
"condition" in the groupby?
> I also tried creating calculated field like this:
>
> Field('year_month', length=20, compute=lambda r:
> '{0:s}-{1:s}'.format(str(r['rate_date'].year()), str(r['rate_date'].month())))
>
>
> But, when I try to read year_now - it is always None (I always truncate
> and insert rows, so calculated field should be calculated).
>
> Any ideas how to solve this?
>
>
Good luck!
/dps
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.