开发者

Imagefield in Inline formset not populated

I have this piece of code:

vehicle = get_object_or_404(Vehicle, stock_number=stock_number)

if request.method == 'POST':
    vehicle_form = VehicleForm(request.POST, instance=vehicle)
    photos = PhotosFormSet(request.POST, request.FILES, instance=vehicle)
    if vehicle_form.is_valid() and photos.is_valid():
        vehicle = vehicle_form.save()
        photos.save()

        request.user.message_set.create(message='The vehicle "%s" was edited
          successfully.' % vehicle.__str__())
        return HttpResponseRedirect("/vehicles/details/%s/" % stock_number)
else:
    vehicle_form = VehicleForm(instance=vehicle)
    photos = PhotosFormSet(instance=vehicle)

return render_to_response('vehicles/vehicles-add-edit.html',  
   {'vehicle_form':vehicle_form, 'photos': photos,}, 
   context_instance=RequestContext(request))

The forms are initialize开发者_Go百科d correctly except the ImageField in PhotosFormSet.


What do you mean when you say it's not initialized? Do you mean populated with the original data?

HTML file input fields are never populated with existing data - this is a browser restriction, nothing to do with Django. It's a security measure, to stop malicious sites tricking you into uploading arbitrary content from your computer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜