我想将我的邮政编码更改为 ''
如果它None
但无法正确访问 country_code 参数来执行此操作。我究竟做错了什么?
class AddressSchema(Schema):
def _postal_check(self, postal):
allowed_countries = ["GE","BT","HK","MO"]
postal_code = postal.postalCode
country_code = postal.countryCode
if postal_code is None and country_code in allowed_countries:
postal_code = ''
return postal_code
countryCode = fields.Str(validate=Length(equal=2), required=True)
postalCode = fields.Method(serialize='_postal_check', allow_none=True, required=True)