I am getting data from different APIs in DRF. However, to enforce modularity I need to serialize the JSON response and make a 'fake' model for each API endpoint I am calling.
I have already created a model and a serializer for an endpoint, but I need to make another API call while serializing previous response I need to modify some of the fields.
from rest_framework import serializers
from django.db import models
from ..nlp_utils.google_nlp import GoogleNLP
class Search(models.Model):
title = models.CharField(blank=True, default='')
link = models.CharField(blank=True, default='')
snippet = models.CharField(blank=True, default='')
description = models.CharField(blank=True, default='')
sentiment_score = models.FloatField(blank=True, default=0.0)
sentiment_magnitude = models.FloatField(blank=True, default=0.0)
class SearchResultSerializer(serializers.ModelSerializer):
class Meta:
model = Search
fields = ('title', 'link', 'snippet', 'description','sentiment_score', 'sentiment_magnitude')`
here I need to call some more endpoints and populate sentiment_score and sentiment_magnitude