Currently I am developing a image gallery django project. The user can upload images, and later upload a 'result' to each of the images. I know that I have to override the update(...) function, but I think I need help here with the Base64ImageFiled.
Step by step:
- User uploads image (result = null)
- Image gets stored in cloud
- User uploads result to a specified image (need help here)
Here is my current structure:
class Image(models.Model):
project = models.ForeignKey(Project)
image = models.ImageField(upload_to='images')
result = models.ImageField(upload_to='results')
class ImageSerializer(serializers.ModelSerializer):
project = ProjectSerializer(read_only=True, required=False)
image = Base64ImageField(max_length=None, use_url=False)
result = Base64ImageField(max_length=None, use_url=False, required=False)
class ProjectImagesViewSet(viewsets.ViewSet):
queryset = Image.objects.select_related('project').all()
serializer_class = ImageSerializer
def list(self, request, project_pk=None):
queryset = self.queryset.filter( project__name = project_pk)
serializer = self.serializer_class(queryset, many=True)
return Response(serializer.data)
def update(self, request, pk=None, project_pk=None):
print(request.data['result'])
???