Hi,

I'm writing an application that recieves a file from an outside source
(not through a view though) which is written to the tmp directory and
then writing it into the db through the FileField. Obviously the file
must also be written to a path which can be retrieved later by just
calling .path from the model.
I've finally been able to make it work through the code below:

    fp = '/tmp/tmpfile.jpg'
    f = open(fp, 'r')
    myfile = File(f)

    user = User(name='username')
    ti = Images(user=user)
    ti.image.save(myfile.name, myfile)  # 1

My model is as follows:

class User(models.Model):
...
...

class Images(models.Model):

    user       = models.ForeignKey(User)
    image      = models.ImageField(upload_to="images/%Y/%m/%d",
null=True)

It took me sometime to figure # 1 out (http://scottbarnham.com/blog/
2008/08/25/dynamic-upload-paths-in-django/), and my question is, where
is the documentation that says you can do ImageField.save() and have
the data written to the db and at the same time make the file be
written to the correct path on disk?



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to