Maybe not the best way, but just for testing, I tried this:

<model>
db.define_table('person',
                Field('unikey','id',compute=lambda r: r.fname+r.lname),
                Field('fname'),
                field('lname')
                )
</model>
got an error because the 'id' needs to be int

<error>
File "/home/rochacbruno/projects/web2py/gluon/dal.py", line 805, in expand
return self.represent(expression,field_type)
File "/home/rochacbruno/projects/web2py/gluon/dal.py", line 1096, in
represent
return str(int(obj))
ValueError: invalid literal for int() with base 10:
</error>

Then I tried with integers and works ok.

person.unikey = 12
person.fname = 1
person.lname = 2

Is there a way to have string fields as primary keys?

Reply via email to