As often happens to me, things are much less complicated than i figure out

I loose hours running after UploadedFile, HttpRequest, etc.
Finally, it was my fault, a wrong path

Using os.path.join(settings.MEDIA_ROOT, 'images') create a new tree from static folder

Using os.path.join(settings.MEDIA_URL, 'images') return '/static/images' that gives error (path does not exist) while using 'static/images' it works now


(it's a test command, in real example i will load name from a file passed by args)
------------------------------------------------------------------------------------------------------------------------------
from django.core.management.base import BaseCommand, CommandError
import os

ffiles = []
ffiles.append('/mnt/hostdir/project/fotoalkatron/SNC110.jpg')
ffiles.append('/mnt/hostdir/project/fotoalkatron/SNC111.jpg')
ffiles.append('/mnt/hostdir/project/fotoalkatron/SNC112.jpg')

class Command(BaseCommand):
    def handle(self, *args, **options):
        _upload_img()
def _upload_img(fname):
    for fpathname in ffiles:
        fname = os.path.split(fpathname)[1]
        _dst= os.path.join( 'static/images', fname)
        myfl = open(fpathname,'r')
        cntn = myfl.read()
        myfl.close()
        fdst = open(_dst,'wb')
        fdst.write(cntn)
        fdst.close()
-------------------------------------------------------------------------------------------------------------------------------


On 05/08/2012 01:19 AM, kooliah wrote:
I need to upload a list of images to a project.
I've found tons of pages about how to upload a file using a form...(that's clearly written on django official docs) :-)

But i need to do it by a custom django-admin command because i have to link theese files(900) to respective records in the project

I tryed with shutil.copy too, but it copies files and immediately delete it. i saw them by file manager in the right folder, but after 1-2 seconds they disappeared.

So i have a list
f[1]='/path/to/source/image1.jpg'
f[2]='/path/to/source/image2.jpg'
f[3]='/path/to/source/image3.jpg'
.
.
f[n]='/path/to/source/imagen.jpg'

and i need to upload to

os.path.join(settings.MEDIA_ROOT, 'images')

Does someone already done it WITHOUT USING FORMS, or can help me...

Thanks to all

Alkatron


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