On 8/21/06, Sean <[EMAIL PROTECTED]> wrote: > > Hi, > I'm trying to write a batch insert view that gets data from a > > object-template, does some modification to the template (increment some > counters) and displays a form for each new object to be created. (I'm > adding Media files which are selected in a previous view, that why I > iterate over files) > The view looks like this: > > manipulator = Media.AddManipulator() > > form_list=list() > errors = {} > for file in files: > #assign new value to template object > template.media_signature = > incSignature(template.media_signature) > new_data = template.__dict__ > new_data["filename"] = file > form = forms.FormWrapper(manipulator, new_data, errors) > form_list.append(form) > > When the loop finishes I end up with a list of identical formWrapper > Objects, which is not what I expected.
Looks like each created instance of FormWrapper is sharing the same instance of the new_data dictionary. Instead of just referencing the dictionary, try copying it: new_data = dict(template.__dict__) By the way, be really careful about accessing the __dict__ attribute in Django code. Django sprinkles all kinds of interesting stuff into its own objects, so you may sometimes get a surprise. Alan. -- Alan Green [EMAIL PROTECTED] - http://bright-green.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 -~----------~----~----~----~------~----~------~--~---