It cannot be done because the ID is assigned by the database engine
(after) the record is inserted, not before.
This would require two operations 1) insert empty record, 2) update
the field. Web2py should not do this automatically because there is
the possibility that another thread accesses the record while in
between 1 and 2.

Massimo

On Oct 24, 1:00 pm, DJ <[email protected]> wrote:
> Hi there,
>
> There must be a simple way to do this, but I can't seem to figure it
> out. I would like a field (name) to populate itself automatically when
> a database record is created.
>
> # test table
> db.define_table("animal",
>     SQLField("name","string",length=20,notnull=True,default="ANML-" +
> str(db.animal.id) ), # this fails
>     SQLField("sex", db.sex)
>     )
>
> after a create action, I would like the following result:
> animal.id = 1
> animal.name = ANML-1
> ....
>
> Is this possible? Thanks for your help!
>
> -Sebastian
>
> PS: would be nice to have 'ANML-000001' with zeros padded according to
> id number (eg. ANML-000299)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to