B
B
B1ackGh0st2020-06-03 14:37:37
Flask
B1ackGh0st, 2020-06-03 14:37:37

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


I search the subscriber table like this:

search_text = request.form['search']

Subscriber.query.filter(text("Subscriber.name ~* '" + search_text + "'")).order_by(Subscriber.name.asc())


How can I display search results from both the position table and the subscriber?

Help me please?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question