我有一个非常独特的问题,在搜索互联网后,找不到所需的解决方案。我需要在字段之间创建依赖关系。即,如果您为field1提供值,则必须为field2和field3提供值。全有或全无。
execute dbms_xdb.setListenerLocalAccess(l_access => FALSE);
答案 0 :(得分:1)
class MySchema(Schema):
field1 = field.String()
field2 = field.String()
field3 = field.String()
other_field = field.String(required=True)
@validates_schema
def validate_required_fields(self, data):
if 'field1' in data:
missing_fields = [f for f in ('field2', 'field3') if f not in data]
if missing_fields:
raise ValidationError('Missing fields: {}'.format(missing_fields))
(顺便说一句,如果是字段名称,则无需指定load_from
。)
答案 1 :(得分:0)
@Jonathan Rys。这是我最初使用的解决方案,它不是很干净,但是可以,但是我建议使用@Jerome代码。
@pre_load(pass_many=True)
def validate_existing_account_info(self, data, many):
print(data)
#raise ValidationError(data)
if 'field1' not in data and 'field2' not in data and 'field3' not in data:
pass
elif 'field1' in data and 'field2' not in data or 'field3' not in data:
raise ValidationError("Must provide all the required info")
elif 'field3' in data and 'field1' not in data or 'field2' not in data:
raise ValidationError("Must provide all the required info")
elif 'field2' in data and 'field1' not in data or 'field3' not in data:
raise ValidationError("Must provide all the required info")