>
> db.define_table('state',
>    Field('country_id', db.country),
>    Field('name', unique=True),
> #   Field('full_name',compute=lambda row: row.country_id, unique=True),
>    format = '%(name)s')    
> #db(db.country.id==r['country_id']).select().first().name
> #class StateVirtualFields(object):
> #    def namecountryid(self):
> #        return str(self.state.country_id)+self.state.name
> #db.state.virtualfields.append(StateVirtualFields())
>
> #db.state.full_name = Field.Virtual(lambda row: row.country_id)
> db.state.fullname.compute = lambda row: str(row.country_id)+row.name 
>
> 1. db.state.fullname.compute doesnot work at all.
>

Is that the exact code you ran? If so, you have not defined a "fullname" 
field anywhere.
 

> 2. if I use Field('full_name',compute=lambda row: row.country_id, 
> unique=True), for some reason it does *NOT* access country_id properly.
>

What do you mean it doesn't access it properly? Show the code you are using 
to insert into the table.

If you are using a form to insert records and want to ensure the 
combination of two fields is unique, you might also consider using an 
onvalidation function (see 
http://web2py.com/books/default/chapter/29/7#onvalidation) or something 
like this: https://groups.google.com/d/msg/web2py/CRPySzABQTk/8jylUabyFTQJ.

Anthony

Reply via email to