我是Odoo的新手,我已经阅读了很多有关该主题的教程和文档。
我只想知道如何在前端视图中将数据保存到模型中。
所以我有一个带有一些输入的模板表单:
templates.xml
<form action="/seatReservation/post" method="post" enctype="multipart/form-data">
<input type="text" name="name" required="True" placeholder="Your Name*"/>
<input type="text" name="email" required="True" placeholder="Your Email*"/>
<button>Insert</button>
</form>
我有一个操作控制器:
controllers.py
@http.route('/seatReservation/post/', type='http', auth="public", methods=['POST'], website=True)
def thankyou(self, name, email):
val = {'name':name, 'email':email}
reservation_obj = http.request.registry['academy.reservations']
reservation_obj.create(http.request.cr, http.request.uid, val, http.request.context)
但是我收到错误,因为找不到http.request.cr
。我做错了什么,我只想要一个简单的表格?
答案 0 :(得分:1)
所以我找到了一个解决方案,我不知道它是否是最聪明的方式,但它有效:
@http.route('/seatReservation/post/', type='http', auth="public", methods=['POST'], website=True)
def thankyou(self, **kwargs):
reservation_obj = http.request.env['academy.reservations']
reservation_obj.create(kwargs)