def get_file_path(instance, filename):
ext = filename.split('.')[-1]
filename = "%s.%s" % (str(instance.uuid), ext)
return os.path.join('uploads','data', filename)
class Image(models.Model):
name = models.CharField(blank=True, max_length=250)
image = models.FileField(upload_to=get_file_path)
uuid = UUIDField(auto=True)
class File(models.Model):
def make_upload_path(instance, filename):
name, extension = os.path.splitext(filename)
filename = '%s%s' % (slugify(name), extension)
d = datetime.datetime.now()
return u'upload/%s/%s/%s/%s' % (instance._meta.app_label,
instance._meta.module_name,
d.strftime('%d_%m_%Y'),
filename.lower())
file = SorlImageField(upload_to=make_upload_path, verbose_name='иконка',
blank=True)