Re: using File storage

2008-08-28 Thread julianb
On Aug 28, 8:53 pm, julianb <[EMAIL PROTECTED]> wrote: > I tried several things, I think Marty's solution was among them. It > did not throw errors, but the file I got was 0 bytes. I will try again > and check if I made a mistake or so... Okay, I solved the puzzle. The following works: big =

Re: using File storage

2008-08-28 Thread julianb
On Aug 28, 8:44 pm, "Tim Kersten" <[EMAIL PROTECTED]> wrote: > This should fix the error you got: > > import StringIO > from django.core.files import File > f = StringIO.StringIO() > f.name, f.mode = 'data.xml', 'r' > f.write(data) > myfile = File(f) >

Re: using File storage

2008-08-28 Thread Tim Kersten
Oh, I should have seen that coming. (That's the bad thing when you write code without testing it yourself... something is often missed :-) This should fix the error you got: import StringIO from django.core.files import File f = StringIO.StringIO() f.name, f.mode = 'data.xml', 'r' f.write(data)

Re: using File storage

2008-08-28 Thread julianb
On Aug 28, 6:03 pm, "Tim Kersten" <[EMAIL PROTECTED]> wrote: > There's probably a better way than this though so you might want to > wait for other replies. > > import StringIO > from django.core.files import File > f = StringIO.StringIO() > f.write(data) > myfile = File(f) >

Re: using File storage

2008-08-28 Thread Tim Kersten
> Chart.objects.create(xml=default_storage.save('data.xml', ContentFile(data))) ha, I was almost certain that django wouldn't make it as hard as I had explained it. :-D Glad to see it's this easy! Tim ^,^ --~--~-~--~~~---~--~~ You received this message because

Re: using File storage

2008-08-28 Thread Marty Alchin
On Thu, Aug 28, 2008 at 11:44 AM, Jiri Barton <[EMAIL PROTECTED]> wrote: > I would like Django to take care of the file naming for me. I would > like to use a one-liner such as > > Chart.objects.create(xml=default_storage.save('data.xml', data)) You're nearly there for getting this to work, it's

Re: using File storage

2008-08-28 Thread Tim Kersten
iirc, you can use http://docs.python.org/lib/module-StringIO.html to have a file like object from a string, and use that to make your django File object ( http://www.djangoproject.com/documentation/files/#the-file-object ). There's probably a better way than this though so you might want to wait

using File storage

2008-08-28 Thread Jiri Barton
What is the preferred way of storing generated content into file models? class Chart(models.Model): xml = models.FileField(upload_to='charts') ... I would like compute the image on the fly, using some data in the database. How should I store the generated data? How should I use File