The snippet below defines a table that stores comments that are
created. The 1st field `user` records the user id of the user who
created the record. I am trying to set the default value to the
current authenticated user, using "auth.user_id" as suggested in
Chapter 13 of the web2py book.
Although the transaction is successful, the value recorded is "None".
I have also used "auth.user.id" but this leads to "AttributeError:
'NoneType' object has no attribute 'id"
Would anyone please kindly explain to me why "auth.user.id" and
"auth.user_id" are failing as described?
db.define_table('comment',
Field('user', custom_auth_table, default=auth.user_id,
writable=False, notnull=True),
Field('question', 'reference question', writable=False,
notnull=True),
Field('text', 'text', length=512, required=True,
requires=IS_NOT_EMPTY()),
Field('created', 'datetime', default=request.now, writable=False,
readable=False, notnull=False),
format='%(user)s on %(question)s'
)