serializers.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:gennotes 作者: madprime 项目源码 文件源码
def create(self, validated_data):
        """
        Check that all required tags are included in tag data before creating.
        """
        if ['tags', 'variant'] != sorted(validated_data.keys()):
            raise serializers.ValidationError(detail={
                'detail': "Create (POST) should include the 'tags' and "
                "'variant' fields. Your request contains the following "
                'fields: {}'.format(str(validated_data.keys()))})
        if 'tags' in validated_data:
            for tag in Relation.required_tags:
                if tag not in validated_data['tags']:
                    raise serializers.ValidationError(detail={
                        'detail': 'Create (POST) tag data must include all '
                        'required tags: {}'.format(Relation.required_tags)})
        return super(RelationSerializer, self).create(validated_data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号