I've got a problem with file upload in django. I found some generic
documentation like this:

http://www.djangoproject.com/documentation/model-api/#filefield
http://www.djangoproject.com/documentation/faq/#how-do-i-use-image-an...

Reading that pages, I suppose that the file uploading copy into my
MEDIA_ROOT happens automatically when I save my record.
The problem is that the file name is saved into my database table, but
the file isn't saved into the MEDIA_ROOT directory in the filesystem.
Where am I wrong? Here is the code (I use django SVN version under
Windows XP):

# models.py

class Auto(models.Model):
    [...others field...]
    foto = models.ImageField(upload_to="images/auto/", blank=True,
null=True)

# forms.py

class AddImageForm(forms.Form):
    immagine = forms.ImageField(label='Immagine:', required=True)

# views.py

def addphotoauto(request, id):
    if request.method == 'GET':
        form = AddImageForm()
        return render_to_response('auto/aggiungi_foto.html', {'form':
form})
    if request.method == 'POST':
        form = AddImageForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                a = Auto.objects.get(id__exact = id)
                a.foto = form.cleaned_data.get('immagine')
                a.save()
                # TODO: save file
                return HttpResponseRedirect('/')
            except Exception, e:
                # exception handling
        else:
            return render_to_response('auto/aggiungi_foto.html',
{'form': form})
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to