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: attribute1 = pb.attr() attribute2 = pb.attr(default=None)
class TestModel: attrib1 = pb.attr(name='attribute1') attrib2 = pb.attr(name='attribute2')
class Occupation: title = pb.attr() address = pb.field() employees = pb.field(converter=int)
class TestModel: attrib1 = pb.attr() attrib2 = pb.attr()
class TestModel: attribute = pb.attr()
class TestModel: element1 = pb.attr()
class TestModel: attrib = pb.attr(default=None)