def save_file_in_node(obj): new_file_node = FileNode(file=obj.file, node_type=FileNode.FILE, has_metadata=True) new_file_node.name = os.path.basename(new_file_node.file.name) # using os.path.splitext(), foo.tar.gz would become foo.tar_2.gz instead of foo_2.tar.gz split = multi_splitext(new_file_node.name) new_file_node.make_name_unique_numbered(split[0], split[1]) # Determine various file parameters # new_file_node.size = new_file_node.file.size new_file_node.extension = split[2].lstrip('.').lower() new_file_node.width, new_file_node.height = (None, None) new_file_node.media_type = FileNode.mimetype_to_media_type(new_file_node.name) new_file_node.slug = slugify(new_file_node.name) new_file_node.has_metadata = new_file_node.check_minimal_metadata() new_file_node.title = obj.title new_file_node.file = str(obj.file) super(FileNode, new_file_node).save() obj.file_node = new_file_node obj.save()