First time asking here, I'll try to sound smart! So, I've got a model called 'Article', and I've populated its 'text' field with 1000+ chars of text. How can I make it so I only send the first 200 chars of the 'text' field when I send an 'Article' serialized object through an endpoint?
views.py
class ArticleScrape(generics.ListAPIView):
queryset = Article.objects.all()
serializer_class = ArticleSerializer
def list(self,request):
serializer = ArticleSerializer(queryset, many=True)
return Response(serializer.data)
serializers.py
class ArticleSerializer(serializers.ModelSerializer):
authors = EachAuthorSerializer(many=True,read_only=True)
tags = EachTagSerializer(many=True,read_only=True)
text = serializers.CharField(max_length=200)
class Meta:
model = Article
exclude=('id',)
Do I need to perform this operation in the queryset? in the serializer? Do I annotate a field? I've tried many of this with no succes. Thanks in advance for the help!