serializers.py 文件源码

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

项目:micromasters 作者: mitodl 项目源码 文件源码
def validate(self, attrs):
        """
        Assert that filled_out can't be turned off and that agreed_to_terms_of_service is true
        """
        if 'filled_out' in attrs and not attrs['filled_out']:
            raise ValidationError("filled_out cannot be set to false")

        if 'agreed_to_terms_of_service' in attrs and not attrs['agreed_to_terms_of_service']:
            raise ValidationError("agreed_to_terms_of_service cannot be set to false")

        # Postal code is only required in United States and Canada
        country = attrs.get("country", "")
        postal_code = attrs.get("postal_code", "")
        if country in ("US", "CA") and not postal_code:
            raise ValidationError("postal_code may not be blank")

        return super(ProfileFilledOutSerializer, self).validate(attrs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号