Skip to content

Instantly share code, notes, and snippets.

@bsnux
Created February 14, 2013 11:57
Show Gist options
  • Save bsnux/4952342 to your computer and use it in GitHub Desktop.
Save bsnux/4952342 to your computer and use it in GitHub Desktop.
Creating a Django FileField from shell
from django.core.files import File
f = File(open('path_to_file','r'))
m = MyModel.objects.create(one_field='value')
m.file_field = f
m.save()
@Ravindrakumara
Copy link

Ravindrakumara commented Jul 13, 2021

Hello;
Need help for i use craete pdf in for loop have save in side object. let me know do;

c = canvas.Canvas(pdf_file + ".pdf", pagesize=A5)
for ab in ["Red","Green","Black"]:
c.save()
color.object.create(pdf=ab)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment