Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
component_error.py 689 B
from rest_framework.serializers import PrimaryKeyRelatedField, CharField, IntegerField
from ..models.component_error import ComponentError
from .utils import NotNullModelSerializer


class ComponentErrorSerializer(NotNullModelSerializer):
    failing_elements = PrimaryKeyRelatedField(many=True, read_only=True)
    component_id = IntegerField(source='component.component_id')
    component_type = CharField(source='component.type')

    class Meta:
        model = ComponentError
        fields = '__all__'
        depth = 2

    def __init__(self, *args, **kwargs):
        self.Meta.depth = kwargs.pop('depth', 2)
        super(ComponentErrorSerializer, self).__init__(*args, **kwargs)