I'm trying to submit form from Qweb. How can I insert form values in database?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
If you are using website templates then the usual HTML form and submit function is used. You need to specify a controller path to process the data and should be a controller with a route to do further process. I can explain you with an example.
I am going to submit a blog comment through odoo. So here I defined a form
<form id="comment" t-attf-action="/blogpost/comment" method="POST">
<div class="media">
<span class="pull-left">
<img class="img img-circle media-object" t-att-src="website.image_url(user_id.partner_id, 'image_small')" style="width: 30px"/>
</span>
<div class="media-body">
<input name="blog_post_id" t-att-value="blog_post.id" type="hidden"/>
<textarea rows="3" name="comment" class="form-control" placeholder="Write a comment..."></textarea>
<button type="submit" class="btn btn-primary mt8">Post</button>
</div>
</div>
</form>
note that the method is POST. You can specify GET also. Here the action should reach "/blogpost/comment", so we need to write a controller to route the same.
@http.route(['/blogpost/comment'], type='http', auth="public", website=True)
def blog_post_comment(self, blog_post_id=0, **post):
cr, uid, context = request.cr, request.uid, request.context
if not request.session.uid:
return login_redirect()
if post.get('comment'):
user = request.registry['res.users'].browse(cr, uid, uid, context=context)
blog_post = request.registry['blog.post']
blog_post.check_access_rights(cr, uid, 'read')
self._blog_post_message(user, blog_post_id, **post)
blog_post = request.registry['blog.post'].browse(cr, uid, int(blog_post_id), context=context)
return werkzeug.utils.redirect("/blog/%s/post/%s#comments" % (slug(blog_post.blog_id), slug(blog_post)))
Here In post contains the input values from the form that is submitted as a key-value pair.
What is the use of registry[] here?
you can use ENV instead of the registry, this is an example form old API. the registry is actually a pool of models.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
0
thg 4 25
|
1348 | ||
|
1
thg 3 24
|
1760 | ||
|
0
thg 6 19
|
4208 | ||
Large columns inside a form
Đã xử lý
|
|
1
thg 12 16
|
3076 | |
|
0
thg 2 16
|
3840 |
Get web form or template value in controller: https://goo.gl/SEHNbA
Odoo Controller: https://goo.gl/gPjPas
hope this will helps