[Answered ]-Updating Records with image field in Django?

2👍

Please update your edit view like this:- That line has to change like this-
form = ServerForm(request.POST or None, request.FILES or None, instance=server)

def server_update(request, pk, template_name='servers/server_form.html'):
    server = get_object_or_404(Server, pk=pk)
    form = ServerForm(request.POST or None, request.FILES or None,  instance=server)
    if form.is_valid():
        edit = form.save(commit=False)
        edit.save()
        return redirect('server_list')
    return render(request, template_name, {'form':form})

0👍

Have you tried sending the data manually as a dictionary instead?

form = Form({'charfield': model.charfield, 'imagefield': model.image})

This way you could try some other options. Presumably you need to send the actual file data, so you would end up sending: model.image.read() instead of just model.image

Leave a comment