Created
December 20, 2013 12:05
-
-
Save DrMartiner/8053853 to your computer and use it in GitHub Desktop.
Update file field from django model
http://stackoverflow.com/questions/7514964/django-how-to-create-a-file-and-save-it-to-a-models-filefield?answertab=active#tab-top
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Entity(models.Model): | |
somefile = model.FileField(upload_to='files') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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