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.
加载中,请稍侯......
精彩评论