I have used a function in Django 1.6 to rename my files when they are uploaded through admin, but this does not work in Django 1.8. Anyone know if it is still possible to do this in 1.8?
class Entry(models.Model):def path_and_rename(path):def wrapper(instance, filename):ext = filename.split('.')[-1]# get filenameif instance.pk:filename = "%s-%s.%s" % (instance.pub_date.year,instance.issue, ext)else:# set filename as random strinfilename = "%s.%s" % (uuid.uuid4(), ext) # return the whole path to the filereturn os.path.join(path, filename)return wrappername = models.CharField(max_length=500)pub_date = models.DateTimeField()issue = models.PositiveIntegerField() pdf = models.FileField(blank=True, upload_to=path_and_rename('uploads/pdf'))