formset中的空图像字段无效

时间:2011-08-16 12:50:21

标签: django

为什么形成无效的空图像字段...落入数据库空记录

@login_required
def add_photo(request, gallery_id):
gallery = get_object_or_404(Gallery, pk=gallery_id)
PhotoFormSet = formset_factory(PhotoUploadForm, extra=1)
formset = PhotoFormSet()
if request.method == "POST":
    formset = PhotoFormSet(request.POST, request.FILES)
    if formset.is_valid():
        for form in formset:
            if form.is_valid():
                data = form.save(commit=False)
                data.galleries = gallery
                data.save()
return render_to_response("add_photo.html", {'formset': formset, 'album_id': gallery_id}, context_instance=RequestContext(request))

1 个答案:

答案 0 :(得分:0)

您是否在表单中的文件字段中设置了required = False?

我们能看到表单定义吗?