I made a web form where user enter his informations and upload a file then submit everything , when the action submit occurs the user data will be stored in candidate record , everything is working fine except for the file uploaded , it doesnt appear in the candidate record as if the user hasnt uploaded any file
I have a model named candidate where I have
candidate.py
attachment_ids = fields.Many2many(string="Attachment")
and in candidate_views.xml I have
<record model="ir.ui.view" id="candidate_form_view">
<field name="name">candidate Form</field>
<field name="model">university.candidate</field>
<field name="arch" type="xml">
<form>
<group>
<field name="f_name"/>
<field name="l_name"/>
field name="attachment_ids" widget="many2many_binary" />
</group>
</form>
</field>
</record>
and in the conrollers/main.py I have
@http.route(['/my/account'], type='http', auth='public', website=True)
def account(self, redirect=None, **post):
Attachments = request.env['university.candidate']
name = post.get('attachment').filename
file = post.get('attachment')
attachment_id = Attachments.create({
'name': name,
'type': 'binary',
'datas': base64.b64encode(file.read())
})
partner.update({
'attachment': [(3, attachment_id.id)],
})
and in the website_form.xml I have
<form action="/my/account" method="post" enctype="multipart/form-data">
<div class="form-group">
<div class="col-lg-3 col-md-4 text-right">
<label class="col-form-label" for="attachment_ids">Attachment(s)</label>
</div>
<div class="col-lg-7 col-md-8">
<input type="file" name="attachment_ids" multiple="true"
accept="image/*,application/pdf,video/*"/>
</div>
</div>
</form>