开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜