@@ -197,10 +197,11 @@ def listdir(self, **lookup):
197197
198198 def move_inodes (self , inode_ids ):
199199 """
200- Move all Inodes with the given IDs to the end of this folder.
200+ Move all Inodes with the given IDs to the end of the current folder.
201201 """
202202 parent_ids = set ()
203203 update_inodes = {}
204+ target_ambit , cache_ambits = self .get_ambit (), {}
204205 entries = FolderModel .objects .filter_unified (id__in = inode_ids )
205206 for ordering , entry in enumerate (entries , self .get_max_ordering () + 1 ):
206207 parent_ids .add (entry ['parent' ])
@@ -213,6 +214,15 @@ def move_inodes(self, inode_ids):
213214 proxy_obj .ordering = ordering
214215 proxy_obj .validate_constraints ()
215216 update_inodes .setdefault (proxy_obj ._meta .concrete_model , []).append (proxy_obj )
217+ if entry ['is_folder' ] is False :
218+ if not (source_ambit := cache_ambits .get (entry ['parent' ])):
219+ source_ambit = FolderModel .objects .get (id = entry ['parent' ]).get_ambit ()
220+ cache_ambits [entry ['parent' ]] = source_ambit
221+ if target_ambit .id is not source_ambit .id :
222+ # move payload from source_ambit to target_ambit and delete from source_ambit
223+ with source_ambit .original_storage .open (proxy_obj .file_path , 'rb' ) as readhandle :
224+ target_ambit .original_storage .save (proxy_obj .file_path , readhandle )
225+ source_ambit .original_storage .delete (proxy_obj .file_path )
216226
217227 with transaction .atomic ():
218228 for concrete_model , proxy_objects in update_inodes .items ():
0 commit comments