当前位置: 首页>>代码示例>>Python>>正文


Python SerializerHelper.add_serializer方法代码示例

本文整理汇总了Python中utils.helper.SerializerHelper.add_serializer方法的典型用法代码示例。如果您正苦于以下问题:Python SerializerHelper.add_serializer方法的具体用法?Python SerializerHelper.add_serializer怎么用?Python SerializerHelper.add_serializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.helper.SerializerHelper的用法示例。


在下文中一共展示了SerializerHelper.add_serializer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EffectTagsSerializer

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import add_serializer [as 别名]
    can_create_sets = serializers.BooleanField(read_only=True)
    effects = EffectTagsSerializer()
    diagnostic = serializers.CharField(source='get_diagnostic_display', read_only=True)
    url = serializers.CharField(source='get_absolute_url', read_only=True)
    results = ResultSerializer(many=True)
    comparison_sets = ComparisonSetLinkSerializer(many=True)

    class Meta:
        model = models.Outcome


class ComparisonSetSerializer(serializers.ModelSerializer):
    url = serializers.CharField(source='get_absolute_url', read_only=True)
    exposure = ExposureSerializer()
    outcome = OutcomeSerializer()
    study_population = StudyPopulationSerializer()
    groups = GroupSerializer(many=True)

    class Meta:
        model = models.ComparisonSet


class OutcomeCleanupFieldsSerializer(DynamicFieldsMixin, serializers.ModelSerializer):

    class Meta:
        model = models.Outcome
        cleanup_fields = model.TEXT_CLEANUP_FIELDS
        fields = cleanup_fields + ('id', )

SerializerHelper.add_serializer(models.Outcome, OutcomeSerializer)
开发者ID:JoshAddington,项目名称:hawc,代码行数:32,代码来源:serializers.py

示例2: _IVChemicalSerializer

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import add_serializer [as 别名]
    experiment = serializers.PrimaryKeyRelatedField(read_only=True)
    chemical = _IVChemicalSerializer()
    groups = serializers.PrimaryKeyRelatedField(read_only=True, many=True)
    benchmarks = serializers.PrimaryKeyRelatedField(read_only=True, many=True)
    category = serializers.PrimaryKeyRelatedField(read_only=True)

    def to_representation(self, instance):
        ret = super(MiniIVEndpointSerializer, self).to_representation(instance)
        ret['url'] = instance.get_absolute_url()
        return ret

    class Meta:
        model = models.IVEndpoint


class IVExperimentSerializerFull(IVExperimentSerializer):
    url_update = serializers.CharField(source='get_update_url', read_only=True)
    url_delete = serializers.CharField(source='get_delete_url', read_only=True)
    url_create_endpoint = serializers.CharField(source='get_endpoint_create_url', read_only=True)
    endpoints = MiniIVEndpointSerializer(many=True)


class CleanupFieldsSerializer(DynamicFieldsMixin, serializers.ModelSerializer):

    class Meta:
        model = models.IVEndpoint
        cleanup_fields = model.text_cleanup_fields()
        fields = cleanup_fields + ('id', 'name')

SerializerHelper.add_serializer(models.IVEndpoint, IVEndpointSerializer)
开发者ID:kevmedeiros,项目名称:hawc,代码行数:32,代码来源:serializers.py

示例3: VisualSerializer

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import add_serializer [as 别名]
        ret["settings"] = settings
        return ret

    class Meta:
        model = models.Visual
        exclude = ('endpoints', )


class VisualSerializer(CollectionVisualSerializer):

    def to_representation(self, instance):
        ret = super().to_representation(instance)

        ret['url_update'] = instance.get_update_url()
        ret['url_delete'] = instance.get_delete_url()

        ret["endpoints"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_endpoints()
        ]

        ret["studies"] = [
            SerializerHelper.get_serialized(d, json=False)
            for d in instance.get_studies()
        ]

        return ret


SerializerHelper.add_serializer(models.Visual, VisualSerializer)
开发者ID:shapiromatron,项目名称:hawc,代码行数:32,代码来源:serializers.py

示例4: StudySerializer

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import add_serializer [as 别名]
    study = StudySerializer()
    inclusion_criteria = serializers.StringRelatedField(many=True)
    exclusion_criteria = serializers.StringRelatedField(many=True)
    url = serializers.ReadOnlyField(source="get_absolute_url")
    protocol_type = serializers.ReadOnlyField(source="get_protocol_type_display")
    lit_search_strategy = serializers.ReadOnlyField(source="get_lit_search_strategy_display")
    results = MetaResultLinkSerializer(many=True)

    class Meta:
        model = models.MetaProtocol


class MetaResultSerializer(serializers.ModelSerializer):
    protocol = MetaProtocolSerializer()
    url = serializers.ReadOnlyField(source="get_absolute_url")
    metric = ResultMetricSerializer()
    adjustment_factors = serializers.StringRelatedField(many=True)
    single_results = SingleResultSerializer(many=True)

    def to_representation(self, instance):
        ret = super(MetaResultSerializer, self).to_representation(instance)
        ret['estimateFormatted'] = instance.estimate_formatted
        return ret

    class Meta:
        model = models.MetaResult


SerializerHelper.add_serializer(models.MetaProtocol, MetaProtocolSerializer)
SerializerHelper.add_serializer(models.MetaResult, MetaResultSerializer)
开发者ID:kevmedeiros,项目名称:hawc,代码行数:32,代码来源:serializers.py

示例5: StudyAssessmentSerializer

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import add_serializer [as 别名]
    study = StudyAssessmentSerializer(read_only=True)
    type_display = serializers.CharField(source='get_type_display')
    status_display = serializers.CharField(source='get_status_display')

    class Meta:
        model = models.Task
        fields = '__all__'
        read_only_fields = (
            'id',
            'study',
            'open',
            'started',
            'completed',
        )

    def update(self, instance, validated_data):
        if self.initial_data['owner']:
            owner_id = self.initial_data['owner']['id']
            instance.owner = HAWCUser.objects.get(pk=owner_id)
            instance.save()
        return super().update(instance, validated_data)


class TaskByAssessmentSerializer(TaskSerializer):
    study = StudyAssessmentSerializer(read_only=True)

    class Meta(TaskSerializer.Meta):
        depth = 2

SerializerHelper.add_serializer(models.Task, TaskSerializer)
开发者ID:shapiromatron,项目名称:hawc,代码行数:32,代码来源:serializers.py

示例6: super

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import add_serializer [as 别名]
        ret = super(MetaProtocolSerializer, self).to_representation(instance)
        ret['url'] = instance.get_absolute_url()
        ret['protocol_type'] = instance.get_protocol_type_display()
        ret['lit_search_strategy'] = instance.get_lit_search_strategy_display()
        return ret

    class Meta:
        model = models.MetaProtocol


class MetaResultSerializer(serializers.ModelSerializer):
    protocol = MetaProtocolSerializer()
    statistical_metric = StatisticalMetricSerializer()
    single_results = SingleResultSerializer(many=True)
    adjustment_factors = serializers.StringRelatedField(many=True)

    def to_representation(self, instance):
        ret = super(MetaResultSerializer, self).to_representation(instance)
        ret['url'] = instance.get_absolute_url()
        ret['estimateFormatted'] = instance.estimate_formatted
        return ret

    class Meta:
        model = models.MetaResult


SerializerHelper.add_serializer(models.StudyPopulation, StudyPopulationSerializer)
SerializerHelper.add_serializer(models.AssessedOutcome, AssessedOutcomeSerializer)
SerializerHelper.add_serializer(models.MetaProtocol, MetaProtocolSerializer)
SerializerHelper.add_serializer(models.MetaResult, MetaResultSerializer)
开发者ID:ashyhanov,项目名称:hawc,代码行数:32,代码来源:serializers.py

示例7: StudySerializer

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import add_serializer [as 别名]
    class Meta:
        model = models.StudyQuality
        exclude = ('object_id', 'content_type')


class StudySerializer(serializers.ModelSerializer):

    def to_representation(self, instance):
        ret = super(StudySerializer, self).to_representation(instance)
        ret['study_type'] = instance.get_study_type_display()
        ret['coi_reported'] = instance.get_coi_reported_display()
        ret['url'] = instance.get_absolute_url()
        return ret

    class Meta:
        model = models.Study


class VerboseStudySerializer(StudySerializer):
    assessment = serializers.PrimaryKeyRelatedField(read_only=True)
    searches = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
    qualities = StudyQualitySerializer(many=True, read_only=True)
    identifiers = IdentifiersSerializer(many=True)
    tags = ReferenceTagsSerializer()

    class Meta:
        model = models.Study


SerializerHelper.add_serializer(models.Study, VerboseStudySerializer)
开发者ID:ashyhanov,项目名称:hawc,代码行数:32,代码来源:serializers.py

示例8: HAWCUserSerializer

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import add_serializer [as 别名]
from rest_framework import serializers

from utils.helper import SerializerHelper

from . import models


class HAWCUserSerializer(serializers.ModelSerializer):
    full_name = serializers.CharField(source='get_full_name')

    class Meta:
        model = models.HAWCUser
        fields = ('id', 'full_name', )

SerializerHelper.add_serializer(models.HAWCUser, HAWCUserSerializer)
开发者ID:JoshAddington,项目名称:hawc,代码行数:17,代码来源:serializers.py

示例9: RiskOfBiasSerializer

# 需要导入模块: from utils.helper import SerializerHelper [as 别名]
# 或者: from utils.helper.SerializerHelper import add_serializer [as 别名]
    class Meta:
        model = models.RiskOfBiasScore
        fields = ('id', 'score', 'notes', 'metric')


class RiskOfBiasSerializer(serializers.ModelSerializer):
    scores = RiskOfBiasScoreSerializer(read_only=False, many=True, partial=True)
    author = HAWCUserSerializer(read_only=True)

    class Meta:
        model = models.RiskOfBias
        fields = ('id', 'author', 'active',
                  'final', 'study', 'created',
                  'last_updated', 'scores')

    def update(self, instance, validated_data):
        """
        Updates the nested RiskOfBiasScores with submitted data before updating
        the RiskOfBias instance.
        """
        score_data = validated_data.pop('scores')
        for score, form_data in zip(instance.scores.all(), score_data):
            for field, value in form_data.items():
                setattr(score, field, value)
            score.save()
        return super(RiskOfBiasSerializer, self).update(instance, validated_data)


SerializerHelper.add_serializer(models.RiskOfBias, RiskOfBiasSerializer)
开发者ID:JoshAddington,项目名称:hawc,代码行数:31,代码来源:serializers.py


注:本文中的utils.helper.SerializerHelper.add_serializer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。