Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask-SQLAlchemy #1

Open
Gatalist opened this issue Mar 26, 2022 · 0 comments
Open

Flask-SQLAlchemy #1

Gatalist opened this issue Mar 26, 2022 · 0 comments

Comments

@Gatalist
Copy link

movie_genre = db.Table('movie_genre',
db.Column('movie_id', db.Integer, db.ForeignKey('movie.id')),
db.Column('genre_id', db.Integer, db.ForeignKey('genre.id')),)

class Genre(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), index=True, unique=True)
movies = db.relationship('Movie', backref='genre', lazy='dynamic')

def __repr__(self):
    return self.name

class Movie(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100))
slug = db.Column(db.String(150), index=True, unique=True)
genres_id = db.Column(db.Integer, db.ForeignKey('genre.id'))
release_date = db.Column(db.DateTime, index=True, default=datetime.utcnow)
producer_id = db.Column(db.Integer, db.ForeignKey('producer.id'))
body = db.Column(db.Text(500))
# rating = db.Column(db.String(100))
poster = db.Column(db.String())
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
publication = db.Column(db.DateTime, index=True, default=datetime.utcnow)

genres = db.relationship('Genre', secondary=movie_genre, backref=db.backref('movie', lazy='dynamic'))

def __repr__(self):
    return self.title

def get_absolute_url(self):
    return f'/movie/{self.slug}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant