开发者

Django: Access each form and FileField in formset

开发者 https://www.devze.com 2023-02-06 01:25 出处:网络
How can I iterate thorugh a formset to get each form and FileField for in that form? for file in formset.files:

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

精彩评论

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