I want to do bulk images POST
to the server.
And the same image will be upload to multiple records in Django 1.11 and Django REST 3.6.1
for image in images:
data = {
'type': image_type,
'attribute': {
'dealer_id': int(dealer_id),
},
'defaults': {
'created_user': user,
'updated_user': user,
'image': image,
}
}
for shop_id in shops:
DisplayImage.objects.update_or_create(**data)
First image does not raises the error. During debugging I had try query that DisplayImage
instance, but it returns empty queryset. It is not a problem because ORM may be lazy-commit.
The error I have is I/O Operation on closed file
Update:
To keep attention from the community. I will keep adding information while I am working on this until I give up.
data == copy_data
Out[2]: False
data
Out[3]:
{'attribute': {'dealer_id': 2},
'created_user': <SimpleLazyObject: <User: admin>>,
'image': <InMemoryUploadedFile: コーティング_車内清掃_室内清掃+除菌抗菌消臭_内容.png (image/png)>,
'type': 1,
'updated_user': <SimpleLazyObject: <User: admin>>}
copy_data
Out[4]:
{'attribute': {'dealer_id': 2},
'created_user': <User: admin>,
'image': <InMemoryUploadedFile: コーティング_車内清掃_室内清掃+除菌抗菌消臭_内容.png (image/png)>,
'type': 1,
'updated_user': <User: admin>}
I had tried copy.deepcopy(data)
which is a dict
that I want to create an instance of DisplayImage
, but when the first one went to the database the next one got closed!
I am ware that it must be different object that is the reason why I check the value by data == copy_data
and it returns False