<gh_stars>0
from django.utils.deconstruct import deconstructible

import os
from uuid import uuid4


@deconstructible
class UploadToPathAndRename(object):

    def __init__(self, path):
        self.sub_path = path

    def __call__(self, instance, filename):
        ext = filename.split('.')[-1]
        # get filename
        # if instance.pk:
        #     filename = '{}.{}'.format(instance.pk, ext)
        # else:
        #     # set filename as random string
        filename = '{}.{}'.format(uuid4().hex, ext)
        # return the whole path to the file
        return os.path.join(self.sub_path, filename)

from django.utils.deconstruct import deconstructible

import os
from uuid import uuid4


@deconstructible
class UploadToPathAndRename(object):

    def __init__(self, path):
        self.sub_path = path

    def __call__(self, instance, filename):
        ext = filename.split('.')[-1]
        # get filename
        # if instance.pk:
        #     filename = '{}.{}'.format(instance.pk, ext)
        # else:
        #     # set filename as random string
        filename = '{}.{}'.format(uuid4().hex, ext)
        # return the whole path to the file
        return os.path.join(self.sub_path, filename)
# get filename # if instance.pk: #     filename = '{}.{}'.format(instance.pk, ext) # else: #     # set filename as random string # return the whole path to the file