Hi Esam,

If I understand you correctly, you want to preserve the image data
even if the user used an invalid value in another form field,
rendering the form invalid?

You could:
1. add the image to the user's session, without saving it to the DB.
2. add the image URL to the user's session, showing a thumb it in the
form using the URL.
3. first validate the form, then download the image, preserving the
location of the image in the form field until the form validates
(4. retrieve the image using an AJAX call over the server, before the
form even gets sent
This is how Google Contacts does it. But I consider this option not
within the scope of your question.)

I would first try 3. since that is the easiest. Then to improve the
user experience, I would probably switch to 2.
And if I have time left, I would implement 1.

Good luck! RR

On May 9, 4:46 pm, esam al deen <ass...@gmail.com> wrote:
> i want to make an image uploader using images links on the internet
> (eq: wwww.example.com/image.jpg). The user writes the previous url and
> then my model upload it.
>
> This my code:
>
> form>>
>
> <input id="id_name" type="text" name="name" maxlength="255"
> value="www.example.com/main.jpg" /> view.py
>
> def Post_date():
>
> if request.method == 'POST':
>
> form = Addpic()#simple form to capture data image_url =
> request.POST.get('image') file = urllib.urlopen(image_url) im =
> cStringIO.StringIO(file.read()) # constructs a StringIO holding the
> image img = Image.open(im) save = '/tmp/' + str(int(time.time())) +
> '.gif'
>
> img.save(save) form.image=save
>
> if form.is_valid():
>
> pic = form.save(commit=False) pic.save()
>
> models.py
>
> class Pic(models.Model):
>
> image = ImageWithThumbsField?(upload_to='images', sizes=((128, 128),))
>
> The image uploads but if form.is_valid(): doesn't work and I don't
> know how to add it to the form data. how i can assign the downloaded
> image to my form (form.image=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