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.protocollo.numero_protocollo,limitby=(0,1)).first()
ult_prot = ultimo_protocollo.numero_protocollo
if ieri==oggi:
db.protocollo.numero_protocollo.default= (ult_prot +1)
else:
db.protocollo.numero_protocollo.default= 1
thank you anyway.
Il giorno sabato 6 gennaio 2018 18:16:31 UTC+1, Andrea Santini ha scritto:
>
> need to create an auto increamet Field that reset to 1 every Year.
>
> db.define_table('protocol',Field('n_protocol'),Field('year_protocol',type='datetime',
> writable = False, readable = False, default=request.now,
> requires=(IS_DATETIME(timezone=pytz.timezone("Europe/Gibraltar"),format=('%Y'))))
>
> The field 'n_protocol' must start to 1 auto increment and return to 1 next
> year.
>
> Why the date is correct when i insert data but is not correct when i see
> the data stored in db the date is wrong?
>
> I also tried this:
>
>
>
> ultimo_protocollo= db(db.protocollo.data_protocollo).select().last()
> ieri = ultimo_protocollo.year
> data = datetime.datetime
> oggi = data.year
> db.protocollo.n_protocollo = Field.Virtual('n_protocollo', lambda
> n_protocollo: (n_protocollo ++ 1) if (ieri == oggi) else
> (db.protocollo.n_protocollo =="1"))
>
>
> but i recive error.
>
> Can you please help me?
>
> Thank you guys
>
>
--
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.