Last active
July 30, 2024 09:31
-
-
Save airsoull/6fbcb9461be35724b792 to your computer and use it in GitHub Desktop.
Create temporary file and save model django
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
from django.core.files import File | |
from django.core.files.temp import NamedTemporaryFile | |
data = 'file' | |
file_temp = NamedTemporaryFile(delete=True, suffix='.py') | |
file_temp.write(data) | |
file_temp.flush() | |
Model.objects.create(file=File(file_temp)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment