0
I am creating a database template in my models.py for my Flask application. I have a User table, and each user can have multiple instruments, and one instrument can have multiple users.
In the documentation of Sqlalchemy and of Flask-Sqlalchemy they recommend creating a table and not a template as it is created for user to stop support this relationship, I did as the documentation recommends, but still not understood what refers to the parameter backref.
usuario_instrumento = db.Table('usuario_instrumento',
db.Column('instrumento_id', db.Integer, db.ForeignKey('instrumento.id'), primary_key=True),
db.Column('usuario_id', db.Integer, db.ForeignKey('usuario.id'), primary_key=True)
)
class Usuario(db.Model):
id = db.Column(db.Integer, primary_key=True)
instrumentos = db.relationship('Instrumento', secondary=usuario_instrumento, lazy='subquery',
backref=db.backref('usuarios', lazy=True))
class Instrumento(db.Model):
id = db.Column(db.Integer, primary_key=True)