where are the code that handle image file upload in Django admin page?

18 views
Skip to first unread message

Chuck22

unread,
Dec 21, 2008, 11:33:48 PM12/21/08
to Django users
I have three ImageField in my form and model, I want to know how to
upload the three image files in the form processing code. I found
Django Admin page handles the image file upload nicely. And I want to
do the exactly same work. But I can not find the piece of code that
does the job when searching the Django source code. Can anyone point
to me where these code are located? Or share some code snippets
related to this.

in my model:
image1 = models.ImageField(upload_to='img/bk', blank=True)
image2 = models.ImageField(upload_to='img/bk', blank=True)
image3 = models.ImageField(upload_to='img/bk', blank=True)

in my form processing:

if request.method == 'POST':
f = MyForm(request.POST, request.FILES)
if f.is_valid():
email = f.cleaned_data['email']
title = f.cleaned_data['title']
...

# save the uploaded images
for v in request.FILES:
save_upload_file(v) <---- this is where i am stuck

Chuck22

unread,
Dec 22, 2008, 11:08:05 PM12/22/08
to Django users
Anyone can help on this? I get stuck with image file upload.

krylatij

unread,
Dec 23, 2008, 3:54:48 AM12/23/08
to Django users
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/
here is a sample how to handle file upload

And have tried:
MyForm.save()?
Reply all
Reply to author
Forward
0 new messages