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
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')
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'))
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')
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)
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')