views:

249

answers:

2

I'm uploading images (represented by a FileField) and I need to rename those files when they are uploaded.

I want them to be formated like that:

"%d-%d-%s.%s" % (width, height, md5hash, original_extension)

I've read the documentation but I don't know if I need to write my own FileSystemStorage class or my own FileField class or ... ? Everything is so linked I don't know where to start.

+3  A: 

You don't need to write your own FileStorage class or anything that complicated.

The 'upload_to' parameter on File/ImageFields can take a function that returns the path/file to use.

How to do this has already been answered here

arcanum
A: 

My initial instinct when reading this was that you need to overload the save method on the model, and use the os.rename() method, but that causes a lot of overhead, and is just generally a hassle from start to finish. If you simply want to rename the file, but don't want to make any physical changes to it (resizing, duplicating, etc.), then I'd definitely recommend the approach arcanum suggests above.

Gary Chambers