Tuesday, September 25, 2012

Re: What's the best way to save generated images?

Okay, this may not be the most efficient implementation, but it works:

  # create temporary file
  tmpfile = tempfile.TemporaryFile()
  write to tmpfile

  # wrap temporary file with django.core.files.File
  fileContents = django.core.files.File(tmpfile)
  fileContents.size = tmpfile.tell()  # admittedly, a bit of a hack
 
  # create and save new Model
  model = Chart(**kwargs)
  model.image.save(fn, fileContents)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/ve5L7uRErOIJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment