Odoo 도움말


3 응답
Samo Arko Slovenia
19. 4. 1. 오전 2:50

For uploading multiple files you need to have set the proper enctype in your form tag and have the option for multiple files in your input tag.

<form method="post" class="s_website_form" action="/new-ticket" enctype="multipart/form-data">
    <p><strong>Attachment </strong><input type="file" name="task_attachment" multiple="true"/></p>

In your controller you need to use request.httprequest.files.getlist() to get the files and just store them with a for loop.

if request.httprequest.method == 'POST':
        # ... # code that creates and fills a dictonary with validated data # ... new_task = request.env['project.task'].sudo().create(create_dict) if 'task_attachment' in request.params: attached_files = request.httprequest.files.getlist('task_attachment') for attachment in attached_files: attached_file = attachment.read() request.env['ir.attachment'].sudo().create({ 'name': attachment.filename, 'res_model': 'project.task', 'res_id': new_task.id, 'type': 'binary', 'datas_fname': attachment.filename, 'datas': attached_file.encode('base64'), })  

It's sad that something so basic for websites isn't better documented. I needed to analyze the whole http.py and go trough the wergzeug documentation to find the methods to get it working. 

2 의견
KOURA, Zana Coulibaly Côte d'Ivoire
19. 6. 30. 오후 1:10

It works fine for me. Thank you very much!

Tabla d.o.o., Samo Arko Slovenia
19. 7. 3. 오전 1:45

Nice... no problem.

Keep Informed
1 팔로워
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now