Answer the question
In order to leave comments, you need to log in
How to search multiple db tables (sqlAlchemy)?
Guys help!
there are models
class Position(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), index=True) # Наименование должности
description = db.Column(db.String(255)) # Описание
def __init__(self, name=None):
self.name=name
def __repr__(self):
return self.name
class Subscriber(db.Model):
__tablename__ = 'subscriber'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), index=True) # Имя
# Савязь с должностями
position_id = db.Column(db.Integer, db.ForeignKey('position.id'))
position = db.relationship(Position)
def __init__(self, name=None):
self.name=name
search_text = request.form['search']
Subscriber.query.filter(text("Subscriber.name ~* '" + search_text + "'")).order_by(Subscriber.name.asc())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question