Skip to content Skip to sidebar Skip to footer

Django File Field Update Causing Error Even Though Not Required

I have an app that serves to update certain fields of a model. There are 4 possible fields that could be updated: resolution, upload4, upload5, and upload6. The upload fields are N

Solution 1:

The point is that you are ignoring the validation that form does, and going straight back to the data from the request. So, yes, that will break if the forms are not there. But this is exactly why we use forms.

case.upload4 = form.cleaned_data['upload4']

etc.

It would be even easier if you used a ModelForm; then you could pass case as the instance argument of the form, and just do form.save(), replacing almost all the code inside your is_valid block.

Solution 2:

This will solve the problem.

case.upload4 = request.FILES.get('upload4')
case.upload5 = request.FILES.get('upload5')
case.upload6 = request.FILES.get('upload6')

Post a Comment for "Django File Field Update Causing Error Even Though Not Required"