Example #1
0
class Director(db.Model):
	__tablename__  = 'directors'

	id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.Text())
	movies = db.relationship('Movie', backref='director', lazy='dynamic') # WHAT IS THIS DOING?

	def __init__ (self, name):
		self.name = name
Example #2
0
class Tag(db.Model):
	__tablename__ = 'tags'

	id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.Text()) #WHY IS THIS A METHOD IF INTEGER IS NOT
	#THERE IS NO MOVIES COLUMN< HOW DOES THIS WORK?
	
	def __init__(self, name):
		self.name = name
Example #3
0
class Author(db.Model):

    __tablename__ = 'authors'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Text())
    books = db.relationship('Book', backref='author', lazy='dynamic', cascade='all, delete-orphan')

    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return 'id: {}, name: {}'.format(self.id, self.name)
Example #4
0
class Movie(db.Model):
    __tablename__ = 'movies'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Text())
    director_id = db.Column(db.Integer, db.ForeignKey('directors.id'))
    tags = db.relationship('Tag',
                           secondary='movie_tags',
                           backref=db.backref('movies', lazy='dynamic'))

    #GOT WEIRD ERROR WHEN 'Tag' was 'tag'
    #WHAT DOES SECONDARY DO? WHAT DOES LAZY DO?
    def __init__(self, title, director_id):
        self.title = title
        self.director_id = director_id
Example #5
0
class Book(db.Model):

    __tablename__ = 'books'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Text())
    author_id = db.Column(db.Integer, db.ForeignKey('authors.id'))

    def __init__(self, title, author_id):
        self.title = title
        self.author_id = author_id

    def __repr__(self):
        return 'id: {}, title: {}, author_id: {}'.format(
            self.id, self.title, self.author_id)