Skip to content

Instantly share code, notes, and snippets.

@airsoull
Last active July 30, 2024 09:31
Show Gist options
  • Save airsoull/6fbcb9461be35724b792 to your computer and use it in GitHub Desktop.
Save airsoull/6fbcb9461be35724b792 to your computer and use it in GitHub Desktop.
Create temporary file and save model django
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