class Upload:
def save_files(self, files, folder_name, id):
id = str(id)
path = self.get_path(folder_name, id)
if not os.path.exists(path):
os.makedirs(path)
for image in files:
extensions = str(image).split('.')
millis = str(round(time.time() * 1000))
with open(os.path.join(path, millis + '.%s' % extensions[-1]),
'wb+') as destination:
for chunk in image.chunks():
destination.write(chunk)
Вызов метода:
print('///////////////////')
print(new_obj.id) # = 73
print('///////////////////')
Upload.save_files(request.FILES.getlist('image'), 'product', new_obj.id)
сам метод:
def save_files(self, files, folder_name, id):
id = str(id)
path = self.get_path(folder_name, id)
.......
@staticmethod
def save_files(files, folder_name, id):
id = str(id)
path = Upload.get_path(folder_name, id)
if not os.path.exists(path):
os.makedirs(path)
for image in files:
extensions = str(image).split('.')
millis = str(round(time.time() * 1000))
def process(f):
with open(path + '/' + millis + '.' + extensions[-1],
'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
process(image)