On 01/26/2012 03:44 AM, Tor Nordam wrote:
Hello,

I have a model with a FileField, that I use to store some user
uploaded files. After a while, I changed my mind about where to store
the files, so I was just wondering if there is a way to manually move
a file, and then update the location of the file as stored in the
database. I'm using a plain models.FileField, with no custom Storage
or anything advanced.

Cheers,
Tor

You could write a short script to do the rename, and run it under "./manage.py shell". Of special interest are the os.path.basename() and os.path.join() functions. I haven't worked with FileFields, though, so be wary of my advice.

something like this:
import os.path
from app.models import Model
prefix = #new folder location
ms = Model.objects.all()
for m in ms:
     oldname = m.fileField.?? #get old path name
     basename = os.path.basename(oldname) # Get the filename by itself
     newpath = os.path.join(prefix, basename)
    #store it back on the object
    m.save()


--
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.

Reply via email to