Hello,
I'm building an API based on a RetrieveUpdateAPIView
<https://www.django-rest-framework.org/api-guide/generic-views/#retrieveupdateapiview>
with
a Writable nested serializers
<https://www.django-rest-framework.org/api-guide/relations/#writable-nested-serializers>.
The issue I have is that when I make a PUT request, the response data
contains all the data of the serializer... And the amount of those data is
pretty big.
*How can I modify my code to avoid this behavior? I imagine that this
should be at the level of the view?*
Thanks for your support.
For the record,
Here is the serializer code:
# DatetimeValue serializer
class DatetimeValueSerializer(serializers.ModelSerializer):
class Meta:
model = DatetimeValue
fields = ['date_time', 'value']
# Serializer that includes time series header and date time values
class TimeSeriesValueSerializer(serializers.ModelSerializer):
values = DatetimeValueSerializer(many=True)
class Meta:
model = TimeSeries
fields = ['id', 'name', 'values']
def update(self, instance, validated_data):
ts_name = validated_data.pop('name')
try:
time_series = TimeSeries.objects.get(name=ts_name)
except ObjectDoesNotExist:
raise ValidationError(_(f"Time series doesn't exist"))
values_data = validated_data.pop('values')
for datetime_value in values_data:
try:
DatetimeValue.objects.create(time_series=time_series,
**datetime_value)
except IntegrityError:
raise ValidationError(_(f"ERROR in 'date_time' and/or 'value'
provided. "
f"'date_time' has to be a correct date
time format and 'value' a float. "
f"A 'date_time' has to be unique for a
given time series"))
return time_series
And the view code:
# View to get time series datetime values
class TimeSeriesValueDetail(generics.RetrieveUpdateAPIView):
queryset = TimeSeries.objects.all()
serializer_class = TimeSeriesValueSerializer
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-rest-framework/4a939358-5393-4631-a3c6-49e4ee928edb%40googlegroups.com.