Ejemplo n.º 1
0
class Book(db.Model):
    __tablename__ = 'book'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    name = db.Column(db.String)
    author_id = db.Column(db.Integer, db.ForeignKey('author.id'))
    genre_id = db.Column(db.Integer, db.ForeignKey('genre.id'))
    characters = db.relationship('Character', secondary=books_char_relation, backref=db.backref('characters'),
                                 lazy='dynamic')
Ejemplo n.º 2
0
class Name(db.Model):
    __tablename__ = 'name'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    name = db.Column(db.String)
    persons = db.relationship('Person', backref='carrier')

    def __init__(self, name):
        self.name = name
Ejemplo n.º 3
0
class Person(db.Model):
    __tablename__ = 'person'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    age = db.Column(db.Integer)
    carrier_id = db.Column(db.Integer, db.ForeignKey('name.id'))

    def __init__(self, age, name_id):
        self.age = age
        self.name_id = name_id
Ejemplo n.º 4
0
class UserTable(db.Model):
    __tablename__ = 'user_table'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    age = db.Column(db.INTEGER)
    address = db.Column(db.String(120))

    def __init__(self, name, age, address):
        self.name = name
        self.age = age
        self.address = address
Ejemplo n.º 5
0
class TestTable(db.Model):
    __tablename__ = 'test_table'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    field = db.Column(db.String)
Ejemplo n.º 6
0
class Character(db.Model):
    __tablename__ = 'character'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    name = db.Column(db.String)
Ejemplo n.º 7
0
class IdCard(db.Model):
    __tablename__ = 'id_card'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    count_of_books = db.Column(db.Integer)
    user_id = db.Column(db.Integer, db.ForeignKey('user_table.id'))
    user = db.relationship('User', backref=db.backref('user'))
Ejemplo n.º 8
0
class Genre(db.Model):
    __tablename__ = 'genre'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    name = db.Column(db.String)
    books = db.relationship('Book', backref='genre')
Ejemplo n.º 9
0
class Author(db.Model):
    __tablename__ = 'author'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    name = db.Column(db.String)
    books = db.relationship('Book', backref='author')
    city = db.Column(db.String)
Ejemplo n.º 10
0
class User(db.Model):
    __tablename__ = 'user_table'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    name = db.Column(db.String)
    books = db.relationship('Book', secondary=user_books_relation, backref=db.backref('users'), lazy='dynamic')
Ejemplo n.º 11
0
from service_api.app_database import db

# ======================= Many to Many Relationship ======================= #
books_char_relation = db.Table('books_char_relation',
                               db.Column('book_id', db.Integer, db.ForeignKey('book.id')),
                               db.Column('character_id', db.Integer, db.ForeignKey('character.id'))
                               )


class Character(db.Model):
    __tablename__ = 'character'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    name = db.Column(db.String)


user_books_relation = db.Table('user_books_ralation',
                               db.Column('user_id', db.Integer, db.ForeignKey('user_table.id')),
                               db.Column('book_id', db.Integer, db.ForeignKey('book.id'))
                               )


class User(db.Model):
    __tablename__ = 'user_table'
    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    name = db.Column(db.String)
    books = db.relationship('Book', secondary=user_books_relation, backref=db.backref('users'), lazy='dynamic')


# ======================= One to Many Relationship ======================= #

class Author(db.Model):