DrMartiner
12/20/2013 - 12:05 PM

Update file field from django model http://stackoverflow.com/questions/7514964/django-how-to-create-a-file-and-save-it-to-a-models-filefiel

e = Entity()
# Using File
f = open('/path/to/file')
e.somefile.save(new_name, File(f))
# Using ContentFile
e.license_file.save(new_name, ContentFile('A string with the file content'))
class Entity(models.Model):
    somefile = model.FileField(upload_to='files')