0
我想bulk_create
Person
对象列表的原始分析的API数据的一些列表。 数据包含:Django bulk_create,而填充ImageField
- 编号
- 评论
图片
person = raw_api_data[0] obj = Person( id=person['id'], comment=person['comment'], ) if person['image'] is not None: obj.image.save( '.jpg', ContentFile(person['image'].decode('base-64')), save=False, ) new_persons.append(obj) Person.objects.bulk_create(new_persons)
我希望能够避免的情况下,bulk_create
失败文件系统上创建本地图像文件。 (例如IntegrityError
)
有没有什么办法避免在创建过程本身之前创建文件本身,同时还能够批量创建所有具有其图像的对象?
除了在将对象本身附加到批量列表之前创建内容文件之外,我没有发现任何其他想法。