Coverage for backend/core/plots/PlotSerializer.py: 100%
22 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
1from .Plot import Plot, Series
2from rest_framework import serializers
3from core.auxiliary.models import PropertyInfo, HistoricalValue
4from core.auxiliary.serializers.PropertyInfoSerializer import PropertyHistorySerializer
7# don't return all the property info, just the history
8class PropertyInfoHistorySerializer(serializers.ModelSerializer):
9 history = PropertyHistorySerializer(many=True)
11 class Meta:
12 model = PropertyInfo
13 fields = ["key", "history"]
16class SeriesSerializer(serializers.ModelSerializer):
17 x_data = PropertyInfoHistorySerializer(required=False, read_only=True, source="x")
18 y_data = PropertyInfoHistorySerializer(required=False, read_only=True, source="y")
20 class Meta:
21 model = Series
22 fields = "__all__"
23 extra_kwargs = {
24 "x": {"required": False},
25 "y": {"required": False}
26 }
29class PlotSerializer(serializers.ModelSerializer):
30 series = SeriesSerializer(many=True, read_only=True)
32 class Meta:
33 model = Plot
34 fields = "__all__"
35 read_only_fields = ["id", "series"]