Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5091 Lượt xem

I'm trying to upload multiple files from the Odoo website (student files), and then call a controller with method post to create a record and save the attachment.

this is my module  student.py

ref = fields.Char(string="Ref")
first_name = fields.Char(string="Firstname")
last_name = fields.Char(string="Lastname")
task_attachment = fields.Many2many(comodel_name="ir.attachment",
relation="m2m_ir_identity_card_rel",
column1="m2m_id",
column2="attachment_id",
string="Identity Card")
And this is my controller
@http.route('/create/webstudent', type="http", auth="user", website=True)
def create_webpatient(self, **kw):
if request.httprequest.method == 'POST':
new_task = request.env['university.student'].sudo().create(kw)
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': 'university.student',
'res_id': new_task.id,
'type': 'binary',
'datas_fname': attachment.filename,
'datas': attached_file.encode('base64'),
})

return request.render("om_university.student_thanks", {})
When I click to the submit button this error show up :
ValueError: Wrong value for university.student.task_attachment:
can anybody help me please!
Ảnh đại diện
Huỷ bỏ
Tác giả

And this is my input on web_form.xml :
<input type="file" name="task_attachment" multiple="true"/>

Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 3 24
5307
1
thg 3 24
1820
1
thg 9 22
3966
2
thg 7 22
2510
1
thg 6 22
3021