I've been playing with FileField and file uploading.
I do have a problem that I can't seem to solve; when a file gets
uploaded, it is placed in the media directory under some random
filename the client was using. I would like to normalize this filename
so that
foo.txt
is saved on the server as
MEDIA_ROOT/text/username_fileid.txt
I have tried combining _post_save() and os.rename(...) to some limited
success but am not able to reset my FileField to the new file path (my
assumption is that using save() inside _post_save() causes infinite
recursion, no?). Clearly said strategy is an ugly hack with some major
problems.
Is there an elegant way to do this?
Regards,
Bo
Moving the rename logic to _pre_save() would be the best way of doing
things but I have a problem where I rename the uploaded file into one
based on it's primary key. While in _pre_save(), self.id is None, so
is there a way to access the value that will become the primary key?
Bo