I have this model
class TravelRequests(models.Model):
mission_order = models.FileField(blank=True, null=True, upload_to='mission_order')
where the mission order filefield is not required for the creation of the model but than it will be updated by an another user so he can upload the file. The problem is that when i upload the file when the model is created it doesn't save the file in the /media folder and in the filefield it self it save only the name of the file
this is the ajax request :
var data = new FormData($('.facilities_form').get(0));
var pk = $(this).val()
$.ajax({
type: "POST",
url: '/approve_facilities/' + pk + '/',
data: data,
cache: false,
processData: false,
contentType: false,
success: function(response) {
if (response == 'request_updated') {
Swal.fire({
title: 'The request is approved!',
type: 'success',
allowOutsideClick: false,
}).then((result) => {
if (result.value) {
window.location.href='/'
}
});
}
}
});
this is the view that handle the request
@login_required
def FacilitiesApproveRequest(request, pk):
cordinator_comment = request.POST.get('cordinator_comment', '').strip()
mission_order = request.FILES.get('mission_order')
request_toApprove = TravelRequests.objects.filter(pk=pk)
request_toApprove.update(mission_order=mission_order, facilities_approve_case=True,
facilities_comment=cordinator_comment, facilities_comment_time=timezone.now(),
request_updater=request.user, request_update=timezone.now(),
request_status='facility_approve', facilities_aprove=request.user)
return HttpResponse('request_updated')
this is the html input :
<form class="facilities_form" method="post" enctype="multipart/form-data">
<input type="file" name="mission_order" id="id_mission_order" accept=".pdf,.jpeg,.png,.msg">
</form>
when i use the form to update the field i get this
Only the filename without the path and when i look into the mission order folder i don't find the uploaded file.
Any help will be appreciated.