Created
July 25, 2013 03:15
-
-
Save ir4y/6076668 to your computer and use it in GitHub Desktop.
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
| #Первый вариант использование ContentFile для непосредственной передачи контента в файл | |
| from django.db import models | |
| from django.core.files.base import ContentFile | |
| class Instance(models.Model): | |
| pdf = models.FileField(verbose_name=u'Файл в формате PDF') | |
| instance = Instance() | |
| name = u"somefilename" | |
| instance.pdf.save(name, ContentFile("some pdf value") | |
| instance.save() | |
| #Второй вариант использование временного файла | |
| from django.core.files import File | |
| from django.core.files.temp import NamedTemporaryFile | |
| image_temp = NamedTemporaryFile(delete=True, suffix='.pdf') | |
| image_temp.write("some file content") | |
| image_temp.flush() | |
| instance.pdf = File(image_temp) | |
| instance.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment