0
在我的web2py應用程序中,我使用SQLFORM將數據添加到名爲'review'的數據庫表中。創建字段返回爲'無'
但是,如果created_by字段顯示登錄用戶的名字,則返回值爲none。
任何想法可能是錯的,我該如何糾正這一點?
控制器 - default.py
def addReview():
response.menu = [
(T('Back to Reviews'), False, URL('default', 'index'))
]
review_form = SQLFORM(db.review)
if review_form.process().accepted:
session.flash = 'Review has been added!'
elif review_form.errors:
response.flash = 'Please review the form for errors'
return dict(review_form=review_form)
模型 - db.py
db.define_table('product',
Field('name', requires=[IS_NOT_EMPTY(), IS_ALPHANUMERIC()]),
Field('description', 'text', requires=IS_NOT_EMPTY()),
Field('stock_level', 'integer')
)
db.define_table('review',
Field('product', 'reference product', writable=False, readable=False),
Field('title', requires=IS_NOT_EMPTY()),
Field('body', 'text', requires=IS_NOT_EMPTY()),
Field('created_by', 'reference auth_user', writable=False),
Field('added', default=request.now, writable=False)
)