I have this models.py:
from django.db import models
class Prato(models.Model):
imagem = models.ImageField()
nome = models.CharField(max_length=30)
descricao = models.TextField()
publicar = models.BooleanField()
def __str__(self):
return self.descricao
I would like to create a serializer that returns all the fields. The trick is that I want the "imagem" field to be represented as an inline data uri of the stored image, instead of an url pointing to the image (that would demand an extra request to fetch the image).
This serializer returns the url of the image, i don know how to modify only the ImageField serializer to return data uri of image.
from rest_framework import serializers
from cardapio.models import Prato
class PratoSerializer(serializers.ModelSerializer):
class Meta:
model = Prato
fields = '__all__'