views:

22

answers:

1

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 initialized correctly except the ImageField in PhotosFormSet.

A: 

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.

Daniel Roseman
I meant populated with the original data...how can I have this working?
Stephen
I see what you mean now....I've figured out a way around this. Thanks Daniel
Stephen