Skip to Content
Menu
This question has been flagged
2403 Views

in my backend .py 

attachment_ids = fields.Many2many('ir.attachment', string="Attachments")

in my xml file
<field name="attachment_ids" widget="many2many_binary"/>

in my website template.xml file
<input type="file" multiple="true" name="attachment_ids"
data-show-upload="true" data-show-caption="true" lass="file"
data-show-preview="true" id="attachment_ids.id"/>

in my controller.py
@http.route('/assignment/submited', type='http', auth='public', website=True)
def portal_submited_assignment_of_student(self, **kw):
assignment_ids = request.env['op.assignment.sub.line'].sudo().create(kw)
for assinement in assignment_ids:
assinement.state = 'submit'
values = {}
if kw.get('attachment_ids', False):
Attachments = request.env['ir.attachment']
name = kw.get('attachment_ids').filename
file = kw.get('attachment_ids')
assignment_id = kw.get('assignment_id')
attachment = file.read()
attachment_id = Attachments.sudo().create({
'name': name,
'datas_fname': name,
'res_name': name,
'type': 'binary',
'res_model': 'op.assignment.sub.line',
'res_id': assignment_id,
'datas': attachment.encode('base64'),
})

return request.render("portal_assignments.portal_submited_assignment_of_student",
{'assignment_ids': assignment_ids})
Avatar
Discard