serializers.py 文件源码

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

项目:valhalla 作者: LCOGT 项目源码 文件源码
def validate_molecules(self, value):
        if not value:
            raise serializers.ValidationError(_('You must specify at least 1 molecule'))

        # Set the relative priority of molecules in order
        for i, molecule in enumerate(value):
            molecule['priority'] = i + 1

        # Make sure each molecule has the same instrument name
        if len(set(molecule['instrument_name'] for molecule in value)) > 1:
            raise serializers.ValidationError(_('Each Molecule must specify the same instrument name'))

        if sum([mol.get('fill_window', False) for mol in value]) > 1:
            raise serializers.ValidationError(_('Only one molecule can have `fill_window` set'))

        return value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号