On 2006-02-06, at 16:43 CET, Luke Skibinski Holt wrote:

I'm having trouble trying to set the upload_to path for a filefield
that will contain the user's id or username -

"images/%s" % User.username

obviously doesn't work, but it's exactly what I'm trying to do... can I
set the upload path dynamically somehow?

That's won't work. Currently I'm using following solution:

 * set upload_to to top-level directory or something similar
* in _pre_save I move file to required directory and update file field accordingly

example:

class Image(meta.Model):
        foo = meta.ImageField(upload_to='foo')
        user = meta.ForeignKey(User)

        def _pre_save(self):
                <rename file from foo/dlname to foo/<username>/dlname>
                self.foo = <new file name>
        #
#

Also you can look at http://djangoutils.python-hosting.com/wiki/ ImageStore (model source: http://djangoutils.python-hosting.com/file/ image_store/trunk/models/image_store.py) for complete example.

---
Nebojša Đorđević - nesh
Studio Quattro - Niš - SCG
http://studioquattro.biz/
http://djnesh.blogspot.com/ | http://djnesh-django.blogspot.com/ | http://djangoutils.python-hosting.com/
Registered Linux User 282159 [http://counter.li.org]


Attachment: PGP.sig
Description: This is a digitally signed message part

Reply via email to