[web2py] Re: auto increment field that reset evry year

2018-01-12 Thread tim . nyborg
I've done this with a table with a year as its id: idb.define_table( 'next_id', Field('year', 'id'), Field('next', 'integer'), ) def get_next_id(year): record = idb.next_id(year) if not record: # Auto add new years idb.next_id.insert(year=year, next=1)

[web2py] Re: auto increment field that reset evry year

2018-01-09 Thread Anthony
On Tuesday, January 9, 2018 at 11:03:02 AM UTC-5, Andrea Santini wrote: > > i was looking on the net and solved my problem using this code: > > > protocollo_ieri= db(db.protocollo.anno_registro).select().last() > ieri = protocollo_ieri.anno_registro.year > data = request.now > oggi = data.year > >

[web2py] Re: auto increment field that reset evry year

2018-01-09 Thread Andrea Santini
i was looking on the net and solved my problem using this code: protocollo_ieri= db(db.protocollo.anno_registro).select().last() ieri = protocollo_ieri.anno_registro.year data = request.now oggi = data.year ultimo_protocollo = db(db.protocollo).select(db.protocollo.numero_protocollo,orderby=~db

[web2py] Re: auto increment field that reset evry year

2018-01-07 Thread villas
Comments... 1. This kind of auto-incrementing is not bullet-proof in a high traffic database. Probably better to rely on the DB to compute the field with a trigger or SP. 2. n_protocol should be an integer field? 3. Virtual fields are not saved to the database. Maybe look at Compute instead