Re: ImageField upload_to issue

2013-01-26 Thread Sammael
I'm terribly sorry, my bad. Of course, the second example is:

class Image(models.Model):
image = models.ImageField(upload_to = upload_path('i'), blank=True)
thumbnail = models.ImageField(upload_to = upload_path('t'), blank=True)


суббота, 26 января 2013 г., 3:58:55 UTC+4 пользователь leonardo написал:
>
> There is no t_upload_path
>
>
> 2013/1/25 Sammael 
>
>> Hello, folks!
>>
>> Here is the relevant part of my model:
>>
>> def i_upload_to(instance, filename):
>> return '/'.join([strftime('i/%y%m/%d'), filename])
>>
>> def t_upload_to(instance, filename):
>> return '/'.join([strftime('t/%y%m/%d'), filename])
>>
>> class Image(models.Model):
>> image = models.ImageField(upload_to=i_upload_to, blank=True)
>> thumbnail = models.ImageField(upload_to=t_upload_to, blank=True)
>>
>>
>> It works as expected, but it's really ugly, terrible code. Let's try to make 
>> it a little better:
>>
>> def upload_path(p):
>> return lambda instance, filename: '/'.join([p, strftime('%y%m/%d'), 
>> filename])
>>
>>
>> class Image(models.Model):
>> image = models.ImageField(upload_to=upload_path('i'), blank=True)
>> thumbnail = models.ImageField(upload_to=t_upload_path('t'), 
>> blank=True)
>>
>>
>> In this case 'image' will be uploaded where expected (e.g. 'i/1301/26'), 
>> but thumbnail will be uploaded to directory like 't/1301/25/i/1301/26/' 
>> instead of 't/1301/26'.
>>
>> Any opinions? Where do I make a mistake?
>>
>> Thank you in advance for any advice.
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

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




Re: ImageField upload_to issue

2013-01-25 Thread Leonardo S
There is no t_upload_path


2013/1/25 Sammael 

> Hello, folks!
>
> Here is the relevant part of my model:
>
> def i_upload_to(instance, filename):
> return '/'.join([strftime('i/%y%m/%d'), filename])
>
> def t_upload_to(instance, filename):
> return '/'.join([strftime('t/%y%m/%d'), filename])
>
> class Image(models.Model):
> image = models.ImageField(upload_to=i_upload_to, blank=True)
> thumbnail = models.ImageField(upload_to=t_upload_to, blank=True)
>
>
> It works as expected, but it's really ugly, terrible code. Let's try to make 
> it a little better:
>
> def upload_path(p):
> return lambda instance, filename: '/'.join([p, strftime('%y%m/%d'), 
> filename])
>
>
> class Image(models.Model):
> image = models.ImageField(upload_to=upload_path('i'), blank=True)
> thumbnail = models.ImageField(upload_to=t_upload_path('t'), 
> blank=True)
>
>
> In this case 'image' will be uploaded where expected (e.g. 'i/1301/26'),
> but thumbnail will be uploaded to directory like 't/1301/25/i/1301/26/'
> instead of 't/1301/26'.
>
> Any opinions? Where do I make a mistake?
>
> Thank you in advance for any advice.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




ImageField upload_to issue

2013-01-25 Thread Sammael
Hello, folks!

Here is the relevant part of my model:

def i_upload_to(instance, filename):
return '/'.join([strftime('i/%y%m/%d'), filename])

def t_upload_to(instance, filename):
return '/'.join([strftime('t/%y%m/%d'), filename])

class Image(models.Model):
image = models.ImageField(upload_to=i_upload_to, blank=True)
thumbnail = models.ImageField(upload_to=t_upload_to, blank=True)


It works as expected, but it's really ugly, terrible code. Let's try to make it 
a little better:

def upload_path(p):
return lambda instance, filename: '/'.join([p, strftime('%y%m/%d'), 
filename])


class Image(models.Model):
image = models.ImageField(upload_to=upload_path('i'), blank=True)
thumbnail = models.ImageField(upload_to=t_upload_path('t'), blank=True)


In this case 'image' will be uploaded where expected (e.g. 'i/1301/26'), 
but thumbnail will be uploaded to directory like 't/1301/25/i/1301/26/' 
instead of 't/1301/26'.

Any opinions? Where do I make a mistake?

Thank you in advance for any advice.

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




Re: imagefield upload_to

2011-05-11 Thread Brian Craft
solved this by moving it to the model clean() method, and using
imagefield.file.open() and imagefield.file.read() to get the data for
computing the other fields.

On Wed, May 11, 2011 at 1:28 PM, Brian Craft  wrote:
> I have a model with an imagefield, and some fields that are computed
> from the image. I'm trying to override the "save" method to fill in
> the other fields.
>
> When I test this in the admin, there are two problems: first, the path
> (mymodel.image.path) doesn't honor the upload_to setting on the field.
> It concats MEDIA_ROOT and the file name, w/o the upload_to. (This is
> django 1.2.3). Second, I don't see the file in the filesystem when
> .save() is called. Perhaps save() is the wrong place to do this?
>
> If I don't try to generated the computed fields, the file is created
> in the correct (upload_to) directory, and if I read the object from
> the db, mymodel.image.path is also correct.
>
> Looks like upload_to is only accessed during FieldFile.save(), where
> the self.name is updated, so the path is always wrong before that.
>
> And apparently the file isn't committed to storage until the field is
> saved. Is there some other way to access the file before it is saved?
>

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



imagefield upload_to

2011-05-11 Thread Brian Craft
I have a model with an imagefield, and some fields that are computed
from the image. I'm trying to override the "save" method to fill in
the other fields.

When I test this in the admin, there are two problems: first, the path
(mymodel.image.path) doesn't honor the upload_to setting on the field.
It concats MEDIA_ROOT and the file name, w/o the upload_to. (This is
django 1.2.3). Second, I don't see the file in the filesystem when
.save() is called. Perhaps save() is the wrong place to do this?

If I don't try to generated the computed fields, the file is created
in the correct (upload_to) directory, and if I read the object from
the db, mymodel.image.path is also correct.

Looks like upload_to is only accessed during FieldFile.save(), where
the self.name is updated, so the path is always wrong before that.

And apparently the file isn't committed to storage until the field is
saved. Is there some other way to access the file before it is saved?

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



Admin save_model and ImageField (upload_to)

2011-01-10 Thread galago
Is there any way to get the full path of file, which will be uploaded?
in save_model action i can get obj.image but it gives me only the file name. 
I want to get path with upload_to from model.
Is it possible?

I need it, because I want to make resizing on my image and make its name 
with hash to custrom folder.

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



Re: ImageField upload_to not workin

2008-11-17 Thread elm

Hi Javier,

I am experiencing the same problem with 'upload_to'.  Have you found
the problem?

Thx,

elm

On 14 nov, 18:31, Javier <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've create a model:
>
> class ImagenesLugar(models.Model):
>     archivo = models.ImageField(upload_to="imageneslugar/")
>     texto = models.CharField(max_length=400)
>
> The thing is that when i create a new instance of this model and
> assign instance.archivo to a file then instance.archivo.path does not
> contain myupload_toparameter:
>
> Ie:
>
> my media root is :"/home/media"
> my uploadto is "imageneslugar"
> my file is "image.jpg"
>
> I do:
> instance.archivo = "image.jpg"
>
> then:
> instance.archivo.path is:
> /home/media/image.jpg
> instead of
> /home/media/imageneslugar/image.jpg
>
> what am I missing?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: ImageField upload_to not workin

2008-11-14 Thread Peter Bengtsson



On Nov 14, 9:31 pm, Javier <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've create a model:
>
> class ImagenesLugar(models.Model):
>     archivo = models.ImageField(upload_to="imageneslugar/")
>     texto = models.CharField(max_length=400)
>
> The thing is that when i create a new instance of this model and
> assign instance.archivo to a file then instance.archivo.path does not
> contain my upload_to parameter:
>
> Ie:
>
> my media root is :"/home/media"
> my uploadto is "imageneslugar"
> my file is "image.jpg"
>
> I do:
> instance.archivo = "image.jpg"

Is this pseudo code or does that actually work? I do this:
instance.achivo.save('image.jpg', request.FILES['photo'])

>
> then:
> instance.archivo.path is:
> /home/media/image.jpg
> instead of
> /home/media/imageneslugar/image.jpg
>
> what am I missing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



ImageField upload_to not workin

2008-11-14 Thread Javier

Hi,

I've create a model:

class ImagenesLugar(models.Model):
archivo = models.ImageField(upload_to="imageneslugar/")
texto = models.CharField(max_length=400)

The thing is that when i create a new instance of this model and
assign instance.archivo to a file then instance.archivo.path does not
contain my upload_to parameter:

Ie:

my media root is :"/home/media"
my uploadto is "imageneslugar"
my file is "image.jpg"

I do:
instance.archivo = "image.jpg"

then:
instance.archivo.path is:
/home/media/image.jpg
instead of
/home/media/imageneslugar/image.jpg

what am I missing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: ImageField: upload_to

2008-09-18 Thread lingrlongr

worked like a charm.  thx.

On Sep 18, 5:21 pm, gnijholt <[EMAIL PROTECTED]> wrote:
> I had to define the callable function before it gets called.
> So in your case I'd put it right under class Product(models.model)
> Then you should be able to just do:
>   upload_to=get_image_path
>
> Cheers,
>
> On Sep 18, 10:20 pm, lingrlongr <[EMAIL PROTECTED]> wrote:
>
> > According to the documentation, I can make the upload_to argument a
> > callable (which must receive 2 args):
>
> > class Product(models.Model):
> >     number = models.CharField(max_length=20)
> >     image = models.ImageField(upload_to='')
>
> > I want to build a path so it looks like this (with respect to
> > MEDIA_URL):
> >   images/products//
>
> > def get_image_path(instance, filename):
> >   return 'images/products/%s/%s' % (instance.number, filename)
>
> > I tried:
> >   upload_to='get_image_path'
> >   upload_to=get_image_path
> >   upload_to=get_image_path()
> >   upload_to=self.get_image_path
>
> > How can I accomplish that?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: ImageField: upload_to

2008-09-18 Thread gnijholt

I had to define the callable function before it gets called.
So in your case I'd put it right under class Product(models.model)
Then you should be able to just do:
  upload_to=get_image_path

Cheers,

On Sep 18, 10:20 pm, lingrlongr <[EMAIL PROTECTED]> wrote:
> According to the documentation, I can make the upload_to argument a
> callable (which must receive 2 args):
>
> class Product(models.Model):
>     number = models.CharField(max_length=20)
>     image = models.ImageField(upload_to='')
>
> I want to build a path so it looks like this (with respect to
> MEDIA_URL):
>   images/products//
>
> def get_image_path(instance, filename):
>   return 'images/products/%s/%s' % (instance.number, filename)
>
> I tried:
>   upload_to='get_image_path'
>   upload_to=get_image_path
>   upload_to=get_image_path()
>   upload_to=self.get_image_path
>
> How can I accomplish that?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



ImageField: upload_to

2008-09-18 Thread lingrlongr

According to the documentation, I can make the upload_to argument a
callable (which must receive 2 args):

class Product(models.Model):
number = models.CharField(max_length=20)
image = models.ImageField(upload_to='')

I want to build a path so it looks like this (with respect to
MEDIA_URL):
  images/products//

def get_image_path(instance, filename):
  return 'images/products/%s/%s' % (instance.number, filename)

I tried:
  upload_to='get_image_path'
  upload_to=get_image_path
  upload_to=get_image_path()
  upload_to=self.get_image_path

How can I accomplish that?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: ImageField upload_to Parameter Problem

2007-07-04 Thread lastmohican

And in case anyone is interested in the results (a demo django gallery
application) have a look here:

http://saschashideout.de/wiki/DjangoGalleryTutorial/


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: ImageField upload_to Parameter Problem

2007-07-04 Thread lastmohican

Thanks, this is quite a good idea, the more I think about it the more
I like it, because Images have only one Gallery, but I can change the
gallery for every image if I want, which would lead to the problem of
moving the image file from one directory to another. Your proposal
seems to be the better solution.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: ImageField upload_to Parameter Problem

2007-07-04 Thread Martin Winkler

Am Wed, 04 Jul 2007 01:19:16 -0700
schrieb lastmohican <[EMAIL PROTECTED]>:

> The Problem is, I want a dynamic image
> storage path, something like MEDIA_ROOT+"images/" wont work with
> hundreds of galleries, [...]

Since your primary concern seems to be too many files in one directory,
did you check
http://www.djangoproject.com/documentation/model-api/#filefield
especially the paragraph about "%Y/%m/%d" ?

So you could do this:

image = models.ImageField(upload_to='images/%Y/%m/%d')

Of course the images of one album are not in one directory, but this
solution still makes more sense:
1) Many users might not upload any images at all - so there would be
many empty directories.
2) Some users might upload a whole lot of images - your problem with too
many files in one directory will come up again.

An additional benefit: If you run out of diskspace, you could mount a
different volume under $MEDIA_ROOT/images/2008 for the next year.

And of course django will always know where your images are:

[ i.image for i in Gallery.get(slug="foobar").image_set.all() ]

will get you all images for one gallery.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



ImageField upload_to Parameter Problem

2007-07-04 Thread lastmohican

Hello everybody,

I want to create a gallery app and I have a slight problem, my
models.py
code looks like this:

...
class Gallery(models.Model):
   slug = models.SlugField(...)
   ...

class Image(models.Model):
   ...
   gallery = models.ForeignKey(...)
   image = models.ImageField(
   upload_to=(lambda:'images/%s' % gallery.slug),
   ...,)
...

This won't work, because the ImageField constructor wants "upload_to"
to
be a String and no Funtion. The Problem is, I want a dynamic image
storage path, something like MEDIA_ROOT+"images/" wont work with
hundrets of galleries, I need something like MEDIA_ROOT
+"images/"+gallery.slug . In my Image class "gallery" is a ForeignKey,
which will have the attribute "slug" at runtime, but not at model
creation time, either I am doing something stupid or there is
currently
no way to solve this. Hopefully someone knows a solution.

Sascha Peilicke
--
http://saschashideout.de


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: ImageField upload_to

2006-04-05 Thread Max Battcher

timster wrote:
> Should the super() method work even though I'm not using MR?

No.  super().save() only works in MR.  You'll need the _pre_save() and 
_post_save() hooks in .91 or trunk.

-- 
--Max Battcher--
http://www.worldmaker.net/
"I'm gonna win, trust in me / I have come to save this world / and in 
the end I'll get the grrrl!" --Machinae Supremacy, Hero (Promo Track)

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



Re: ImageField upload_to

2006-04-05 Thread Max Battcher

timster wrote:
> Should the super() method work even though I'm not using MR?

No.  super().save() only works in MR.  You'll need the _pre_save() and 
_post_save() hooks in .91 or trunk.

-- 
--Max Battcher--
http://www.worldmaker.net/
"I'm gonna win, trust in me / I have come to save this world / and in 
the end I'll get the grrrl!" --Machinae Supremacy, Hero (Promo Track)

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



Re: ImageField upload_to

2006-04-05 Thread timster

Thanks for the reply Ian.

I seem to have solved this for the most part. The second message in
that thread was very helpful. I was able to use that solution almost
exactly. I added the following save() method to my model:

def save(self):
if self.image:
import shutil
from os import path
from django.conf import settings
pathname, filename = path.split(self.image)
new_image = path.join(pathname, '%s-%s' %
(str(self.gallery_id), filename))
new_location = path.join(settings.MEDIA_ROOT, new_image)
old_location = path.join(settings.MEDIA_ROOT, self.image)
if new_location != old_location:
shutil.move(old_location, new_location)
self.image = new_image
print self.image
super(Image, self).save()

I decided to add the gallery_id to the image filename rather than as a
subfolder. It still prevents duplicate filenames -- which is what I
wanted -- but it is more simple.

However, when I call the save() function, it chokes on the last line:

>>> from django.models.gallery import galleries, images
>>> i = images.get_object(pk=1)
>>> i.image
'gallery/audi-01.jpg'
>>> i.save()
gallery/1-audi-01.jpg
Traceback (most recent call last):
  File "", line 1, in ?
  File "/.../gallery/models/gallery.py", line 44, in save
super(Image, self).save()
AttributeError: 'super' object has no attribute 'save'

Should the super() method work even though I'm not using MR?


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



Re: ImageField upload_to

2006-04-04 Thread Ian Clelland

On 4/4/06, timster <[EMAIL PROTECTED]> wrote:
> What I would like to do is store the image in a subfolder corresponding
> to the gallery_id. If "Subaru" is gallery_id 1 and "Audi" is gallery_id
> 2, I would want it to look like this:
>
> gallery/1/subaru1.jpg
> gallery/2/audi1.jpg
>
> Is this possible to do in the model? Do I need to tie into the
> _pre_save() method? I couldn't much documentation on ImageField.
>
> It would be even better if the image could be renamed corresponding to
> the image_id, but this might be asking too much.

This is a little bit awkward to do, because the ImageField is just one
field in your model, and doesn't have an id of its own. I've done this
with a custom field class, but it's a bit easier to do by overriding
the save() method of your model.

See this thread from last week for both ways of doing this:
http://groups.google.com/group/django-users/browse_thread/thread/93c024f1523f5323/6bea5b407797e597

Ian Clelland
<[EMAIL PROTECTED]>

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



ImageField upload_to

2006-04-04 Thread timster

I'm trying to create a simple image gallery. Here's what my models look
like. It's very simple, a gallery can have one or more images.

class Gallery(meta.Model):
name = meta.CharField(maxlength=50)

class Image(meta.Model):
gallery = meta.ForeignKey(Gallery)]
image = meta.ImageField(upload_to='gallery/')

If I create two galleries, "Subaru" and "Audi" and upload an image to
each, the images are stored in the gallery/ directory. It would look
like this:

gallery/subaru1.jpg
gallery/audi1.jpg

What I would like to do is store the image in a subfolder corresponding
to the gallery_id. If "Subaru" is gallery_id 1 and "Audi" is gallery_id
2, I would want it to look like this:

gallery/1/subaru1.jpg
gallery/2/audi1.jpg

Is this possible to do in the model? Do I need to tie into the
_pre_save() method? I couldn't much documentation on ImageField.

It would be even better if the image could be renamed corresponding to
the image_id, but this might be asking too much.

Thanks in advance,
Tim Shaffer


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