Django: Access each form and FileField in formset
How can I iterate thorugh a formset to get each form and FileField for in that form?
for file in formset.files:
....
for form i开发者_运维知识库n formset.forms:
....
I'd like the above in the same loop since I need both of them in the same time!
Your question is a little confusing, but if you're looking for your form object and uploaded file in the same loop, it would look like so:
# code
for form in formset.forms:
form.is_valid() # objective #1 accomplished
the_file = form.cleaned_data['my_file_field'] # objective #2 accomplished
If not, please clarify.
精彩评论