class TestModel: field1 = pb.field('element', idx=1) field2 = pb.field('element', idx=2) field3 = pb.wrap('wrapper', pb.field('element'), idx=1) field4 = pb.wrap('wrapper', pb.field('element'), idx=2) nested1 = pb.nested(Nested, idx=1) nested2 = pb.nested(Nested, idx=2)
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 TestModel: element1 = pb.field() element2 = pb.nested(NestedModel, default=None)
class TestModel: elements = pb.as_list(pb.nested(NestedModel))
class TestModel: nested = pb.nested(NestedModel1)
class NestedModel1: nested = pb.nested(NestedModel2)
class TestRootModel: model1 = pb.nested(TestBaseModel) model2 = pb.nested(TestExtendedModel)
class TestModel: element = pb.nested(NestedModel)
class TestModel: nested = pb.nested(NestedModel, default=None)