class AdvertSchema(Schema): id = fields.Integer(dump_only=True) title = fields.String() images_set = fields.Relationship(schema=ImageSchema, many=True, dump_only=True, dump_to='images') description = fields.String() author = fields.Relationship( schema=UserSchema, type_='user', related_url='/api/v1/users/{author_id}', related_url_kwargs={'author_id': '<author.id>'}, include_resource_linkage=False) # timestamp = TimeStampConvertedField() price = fields.Float() timestamp = fields.LocalDateTime('%Y%m%d%H%M%S', dump_only=True) key = fields.Method('ExampleKeyGenerated', dump_only=True) class Meta: type_ = 'advert' additional = ('id', ) def ExampleKeyGenerated(self, obj): return ''.join(('@', str(obj.item))) @post_load def make_advert(self, data): return Adverts(**data)
class AuthenticatedUserSchema(UserSchema): email = fields.String() time_quota = fields.Integer() time_used = fields.Integer() disk_quota = fields.Integer() disk_used = fields.Integer() last_login = fields.LocalDateTime("%c")
class UserSchema(Schema): id = fields.String(dump_only=True, attribute='user_id') user_name = fields.String() email = fields.Email(dump_only=True) first_name = fields.String(allow_none=True) last_name = fields.String(allow_none=True) affiliation = fields.String(allow_none=True) url = fields.Url(allow_none=True) time_quota = Duration(dump_only=True) time_used = Duration(dump_only=True) disk_quota = DataSize(dump_only=True) disk_used = DataSize(dump_only=True) last_login = fields.LocalDateTime("%c", dump_only=True) date_joined = fields.LocalDateTime("%c", dump_only=True) class Meta: type_ = 'users'
class UserSchema(Schema): id = fields.String(attribute='user_id') user_name = fields.String() first_name = fields.String(allow_none=True) last_name = fields.String(allow_none=True) affiliation = fields.String(allow_none=True) url = fields.Url(allow_none=True) date_joined = fields.LocalDateTime("%c") class Meta: type_ = 'users'