def generate_filename(self, instance, filename):
    path_parts = []
    if self.upload_to:
        if callable(self.upload_to):
            (dirname, filename) = os.path.split(self.upload_to(instance, filename))
            path_parts.append(dirname)
        else:
            dirname = force_text(datetime.datetime.now().strftime(force_str(self.upload_to)))
            path_parts.append(dirname)
    upload_subfolder = self.upload_subfolder
    if upload_subfolder:
        extra_dirs = upload_subfolder(instance)
        if isinstance(extra_dirs, string_types):
            warnings.warn('{}.{}.upload_subfolder should return a list to avoid path-separator issues.'.format(instance.__class__.__name__, self.name), UserWarning)
            extra_dirs = os.path.split(extra_dirs)
        path_parts.extend([self.storage.get_valid_name(dir) for dir in extra_dirs])
    path_parts.append(self._get_clean_filename(filename))
    if (django.VERSION >= (1, 10)):
        filename = posixpath.join(*path_parts)
        return self.storage.generate_filename(filename)
    else:
        return os.path.join(*path_parts)
def generate_filename(self, instance, filename):
    path_parts = []
    if self.upload_to:
        if callable(self.upload_to):
            (dirname, filename) = os.path.split(self.upload_to(instance, filename))
            path_parts.append(dirname)
        else:
            dirname = force_text(datetime.datetime.now().strftime(force_str(self.upload_to)))
            path_parts.append(dirname)
    upload_subfolder = self.upload_subfolder
    if upload_subfolder:
        extra_dirs = upload_subfolder(instance)
        if isinstance(extra_dirs, string_types):
            warnings.warn('{}.{}.upload_subfolder should return a list to avoid path-separator issues.'.format(instance.__class__.__name__, self.name), UserWarning)
            extra_dirs = os.path.split(extra_dirs)
        path_parts.extend([self.storage.get_valid_name(dir) for dir in extra_dirs])
    path_parts.append(self._get_clean_filename(filename))
    if (django.VERSION >= (1, 10)):
        filename = posixpath.join(*path_parts)
        return self.storage.generate_filename(filename)
    else:
        return os.path.join(*path_parts)