mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-12 07:54:14 +00:00
POST image data to View
- https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects - https://stackoverflow.com/questions/25390598/append-called-on-an-object-that-does-not-implement-interface-formdata#25390646
This commit is contained in:
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from django.http import JsonResponse
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import DetailView, ListView
|
||||
from django.forms.models import model_to_dict
|
||||
@ -268,6 +269,31 @@ class PartImage(AjaxUpdateView):
|
||||
}
|
||||
|
||||
|
||||
class UploadPartImage(AjaxView):
|
||||
""" View for uploading a Part image """
|
||||
|
||||
model = Part
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
try:
|
||||
part = Part.objects.get(pk=kwargs.get('pk'))
|
||||
except Part.DoesNotExist:
|
||||
error_dict = {
|
||||
'error': 'Part not found',
|
||||
}
|
||||
return JsonResponse(error_dict, status=404)
|
||||
|
||||
print("Files:", request.FILES)
|
||||
uploaded_file = request.FILES['file']
|
||||
|
||||
response_dict = {
|
||||
'success': 'File was uploaded successfully',
|
||||
}
|
||||
|
||||
return JsonResponse(response_dict, status=200)
|
||||
|
||||
|
||||
|
||||
class PartEdit(AjaxUpdateView):
|
||||
""" View for editing Part object """
|
||||
|
||||
|
Reference in New Issue
Block a user