class User: name = pb.attr() surname = pb.attr() age = pb.attr(converter=int) phone = pb.wrap('contacts', pb.field()) emails = pb.wrap('contacts', pb.as_list(pb.field(name='email'))) passport_series = pb.wrap('documents/passport', pb.attr('series')) passport_number = pb.wrap('documents/passport', pb.attr('number')) occupations = pb.wrap('occupations', pb.lst(pb.nested(Occupation)), ns='data', ns_map={'data': 'http://www.test22.org'}) citizenship = pb.field(default='RU')
class User: name = pb.attr() surname = pb.attr() age = pb.attr(converter=int) birth_year = pb.wrap('birthdate', pb.attr('year', converter=int)) birth_month = pb.wrap('birthdate', pb.attr('month', converter=int)) birth_day = pb.wrap('birthdate', pb.attr('day', converter=int)) @property def birthdate(self): return date(year=self.birth_year, month=self.birth_month, day=self.birth_day) @birthdate.setter def birthdate(self, value): self.birth_year = value.year self.birth_month = value.month self.birth_day = value.day phone = pb.wrap('contacts', pb.field()) emails = pb.wrap('contacts', pb.as_list(pb.field(name='email'))) passport_series = pb.wrap('documents/passport', pb.attr('series')) passport_number = pb.wrap('documents/passport', pb.attr('number')) occupations = pb.wrap('occupations', pb.lst(pb.nested(Occupation)), ns='data', ns_map={'data': 'http://www.test2.org'}) citizenship = pb.field(default='RU') @phone.validator def check(self, attribute, value): if not re.match(r'\+\d{11,13}', value): raise ValueError("phone number is incorrect")
class TestModel: field = pb.field() nested = pb.as_list(pb.nested(Nested))
class Nested: fields = pb.as_list(pb.field())
class TestModel: elements = pb.as_list( pb.wrap('element1', pb.as_list(pb.field('element2'))))
class TestModel: elements = pb.as_list(pb.nested(NestedModel))
class TestModel: elements = pb.as_list(pb.wrap('wrapper', pb.field('element')))
class TestModel: element1 = pb.as_list(pb.field())