uhm .... that code will put down your db as soon as "material" gets a few
lines .... a better way is to fetch the latest id using orderby and limit
new_id = db(db.material.id>0).select(db.material.id,
orderby=~db.material.id, limitby=(0,1)).first()
new_id = new_id and new_id + 1 or 1
But.....if you need a serial_no that basically is equal to the id of that
table, you have two better (at least for my point of view) options....
db.define_table('material',
.....
.....
Field("serial_no", "id")
)
or just use the id and name the column in the grid as "serial_no" passing
the colnames in the headers parameters of the grid....
headers = {'material.id' : "Serial No"}
On Monday, February 11, 2013 10:09:12 AM UTC+1, Pankaj Pathak wrote:
>
> Good noon to all,
>
> Is there any technic to set serial no in SQLGRID, i have try following
> code for it but i am not satisfied,
> db.define_table("material",
> Field("serial_no", writable=False,),
> Field("material_type", requires=IS_IN_SET(['Capax',
> 'Opax']), default = "Capax"),
> Field("code"),
> Field("description"),
> Field("unit"),
> Field("price"),
> )
> material_table_ids = [i.id for i in db(db.material).select()]
>
> db.material.serial_no.represent = lambda id,row:
> material_table_ids.index(row and row.id or material_table_ids[-1])+1
>
>
--
---
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/groups/opt_out.