Skip to content
Snippets Groups Projects
Commit 3ff466a0 authored by Mattia Mancini's avatar Mattia Mancini
Browse files

Story OSB-11: Included component error serialization in station test page

parent 89bb053e
No related branches found
No related tags found
2 merge requests!89Monitoring maintenance Epic branch merge,!1Resolve OSB-13 "Monitoringmaintenance "
...@@ -7,7 +7,8 @@ from .error_details import ErrorDetails ...@@ -7,7 +7,8 @@ from .error_details import ErrorDetails
class ComponentError(models.Model): class ComponentError(models.Model):
type = models.CharField(max_length=50) type = models.CharField(max_length=50)
component = models.ForeignKey(Component, on_delete=models.DO_NOTHING) component = models.ForeignKey(Component, on_delete=models.DO_NOTHING)
station_test = models.ForeignKey(StationTest, on_delete=models.DO_NOTHING) station_test = models.ForeignKey(StationTest, on_delete=models.DO_NOTHING,
related_name='component_errors')
details = models.ForeignKey(ErrorDetails, details = models.ForeignKey(ErrorDetails,
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='details', related_name='details',
......
...@@ -9,3 +9,7 @@ class ComponentErrorSerializer(NotNullModelSerializer): ...@@ -9,3 +9,7 @@ class ComponentErrorSerializer(NotNullModelSerializer):
model = ComponentError model = ComponentError
fields = '__all__' fields = '__all__'
depth = 2 depth = 2
def __init__(self, *args, **kwargs):
self.Meta.depth = kwargs.pop('depth', 2)
super(ComponentErrorSerializer, self).__init__(*args, **kwargs)
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
from ..models.station_test import StationTest from ..models.station_test import StationTest
from .component_error import ComponentErrorSerializer
class StationTestSerializer(ModelSerializer): class StationTestSerializer(ModelSerializer):
component_errors = ComponentErrorSerializer(many=True, read_only=True, depth=0)
class Meta: class Meta:
model = StationTest model = StationTest
fields = '__all__' fields = '__all__'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment