I am currently integrating exchange server email to my application. I am able to retrieve attachments from my emails using exchangelib. I am trying to save the attachments into my Django model filefield. However, it is not working with different errors based on different solutions I tried. Any help is appreciated. Thank you. Below are some of my code:
models.py
class Attachments(models.Model):
name = models.CharField(max_length=255)
attachment = models.FileField(upload_to="attachments/")
views.py
for attachment in item.attachments:
if isinstance(attachment, FileAttachment):
attachmentlist.append(attachment.name)
saveattachments = Attachments(
name=attachment.name,
attachment=(attachment.content)
)
saveattachments.save()