class PostVotesSchema(ModelSchema): voter = Related() post = Related() class Meta: model = PostVotes
class CommentSchema(ModelSchema): parent = Related() author = Related() post = Related() class Meta: model = Comment
class AuthorsBooksSchema(ModelSchema): book_id = Related(nested=BookSchema) author_id = Related(nested=AutorSchema) @validates('book_id') def validate_book(self, value): if not Books.filter(Books.id == value).exists(): raise ValidationError("Can't find book!") @validates('author_id') def validate_autor(self, value): if not Autors.filter(Autors.id == value).exists(): raise ValidationError("Can't find author!")
class AuthorBookSchema(BookSchema): book = Related(nested=BookSchema) author = Related(nested=AuthorSchema) class Meta: model = AuthorBook @validates('book') def validate_book(self, book): if not Book.filter(Book.id == book).exists(): raise ValidationError("Can't find book") @validates('author') def validate_author(self, author): if not Author.filter(Author.id == author).exists(): raise ValidationError("Can't find author")
class ArtifactSchema(ModelSchema): task = Related() class Meta: model = Artifact model_converter = ExtendedConverter
class UserSchema(ModelSchema): role = Related(RoleSchema) class Meta: model = User dump_only_pk = False
class PostSchema(ModelSchema): author = Related() #tags = fields.Nested(TagSchema, many=True) class Meta: model = Post
class UserSchema(ModelSchema): role = Related(unknown=ma.EXCLUDE) class Meta: model = User dump_only_pk = False exclude = 'rating',
class UserSchema(ModelSchema): role = Related() class Meta: model = User dump_only_pk = False exclude = 'rating',
class BookSchema(ModelSchema): name = fields.Str(validate=[validate.Length(min=3, max=100)]) ganre_id = Related(nested=GanreSchema) autor = Related(nested=AutorSchema) year = fields.Int(validate=[validate.Length(min=4, max=4)]) publisher = fields.Str(validate=[validate.Length(min=3, max=100)]) class Meta: model = Books @validates('autor') def validate_autor(self, value): if not Autors.filter(Autors.id == value).exists(): raise ValidationError("Can't find author!") @validates('ganre_id') def validate_ganre(self, value): if not Ganre.filter(Ganre.id == value).exists(): raise ValidationError("Can't find ganre!")
class ProjectSchema(ModelSchema): name = fields.Str(validate=[validate.Length(min=3, max=100)], required=True) color = fields.Str( validate=[validate.Regexp('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$')], required=True) user = Related(nested=UserSchema) class Meta: model = Project
class BookSchema(ModelSchema): name = fields.Str(validate=[validate.Length(min=3, max=100)]) author = Related(nested=AuthorSchema) class Meta: model = Book @validates('author') def validate_author(self, value): if not Author.filter(Author.id == value).exists(): raise ValidationError("Can't find author")
class TaskSchema(ModelSchema): title = fields.Str(validate=[validate.Length(min=3, max=100)], required=True) date = fields.Date(required=True) priority = fields.Integer(validate=[validate.Regexp('[0-9]+')]) project = Related(nested=ProjectSchema) class Meta: model = Task @validates('project') def validate_project(self, value): if not Project.filter(Project.id == value).exists(): raise ValidationError("Can't find project")
class RoleSchema(ModelSchema): user_set = Related() class Meta: model = Role
class CommentVotesSchema(ModelSchema): voter = Related() comment = Related() class Meta: model = CommentVotes
class TaskEventSchema(ModelSchema): task = Related() class Meta: model = TaskEvent
class LineitemSchema(ModelSchema): invoice = Related() class Meta: model = Lineitem