On 6/23/07, Bryan Veloso <[EMAIL PROTECTED]> wrote:
>
> > Can't paste the code from the actual app (am under NDA) but the logic
> > in saving the image from form data is here:
> >
> > http://dpaste.com/12731/
>
> The only problem with this, and probably why I'm looking to use #3297
> (which actually didn't work too well anyway), is because I have as
> many as 15 file upload fields on one page. All the examples I've seen
> only take care of one image on a certain form at a time and I don't
> want to duplicate the code up to 15 times.

BTW, Had a typo in the dpaste code. Line 19 should say:

img_obj.save_image_file(uploaded['filename'], uploaded['content'])

You don't have to duplicate code, well not duplicate too much. That's
why the image validation method in the form is separate from the
*_clean methods. In my app, I had to allow up to four simultaneous
uploads. You have to set a limit to the number of uploads because if
you don't you will be bound to hit the limits of your server anyway.

Create a form with the number of image fields numbered in sequence. For example:

img_fld1
img_fld2
img_fld3
...

Then when you do your processing in your view, simply wrap the code
that saves the images in a loop:

for n in range(0, MAX_NUM_UPLOADS):
    img_manip = ImageAttachment.AddManipulator()
    img_obj = img_manip.save()
    uploaded = clean_data['img_fld%d' % n]
    obj.save_image_file(uploaded['filename'], uploaded['content'])

For validation, I haven't tried it yet, but I think you should be able
to implement it using __getattr__ to handle it. That way you don't
have to duplicate validation code.
-- 
_nimrod_a_abing_

http://abing.gotdns.com/
http://www.preownedcar.com/

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