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
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
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.
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
AanmeldenGerelateerde posts | Antwoorden | Weergaven | Activiteit | |
---|---|---|---|---|
|
0
apr. 25
|
1348 | ||
|
1
mrt. 24
|
1760 | ||
|
0
jun. 19
|
4208 | ||
Large columns inside a form
Opgelost
|
|
1
dec. 16
|
3078 | |
|
0
feb. 16
|
3840 |
Get web form or template value in controller: https://goo.gl/SEHNbA
Odoo Controller: https://goo.gl/gPjPas
hope this will helps