Skip to content

Instantly share code, notes, and snippets.

@DrMartiner
Created December 20, 2013 12:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrMartiner/8053853 to your computer and use it in GitHub Desktop.
Save DrMartiner/8053853 to your computer and use it in GitHub Desktop.
class Entity(models.Model):
somefile = model.FileField(upload_to='files')
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'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment