answer from stackoverflow:
http://stackoverflow.com/questions/499964/how-do-you-create-python-methodssignature-and-content-in-code/499982#499982
Python code behaves like this for functions defined in scope of
methods. Use this instead:
for image_name in image_fields:
print "image name is: ", image_name
setattr(new_form, 'clean_' + image_name,
lambda self, iname=image_name: self._clean_photo(iname))
The usage of default keyword argument makes Python remember it at the
time of lambda function creation rather than at the time of its
calling (when it would always take the last image).
yay :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---