python - How to filter by multiple criteria in Flask SQLAlchemy? -


i have database shown below works fine. have user called bob owns space mainspace. boolean see if owner of space. tried apply 2 filters following error.

sqlalchemy.exc.invalidrequesterror: can't compare collection object or collection; use contains() test membership. 

command:

exists = space.query.filter_by(name="mainspace", owner="bob").first() 

database:

space_access = db.table('space_access',     db.column('userid', db.integer, db.foreignkey('user.id')),     db.column('spaceid', db.integer, db.foreignkey('space.id')))  class user(usermixin, db.model):     id = db.column(db.integer, primary_key=true)     username = db.column(db.string(15), unique=true)     email = db.column(db.string(50), unique=true)     password = db.column(db.string(80))     role='admin';      spaces = db.relationship('space', secondary=space_access, backref=db.backref('owner', lazy='dynamic'))  class space(usermixin, db.model):     id = db.column(db.integer, primary_key=true)     name = db.column(db.string(50), unique=true)     type = db.column(db.string(50), unique=true) 

try this:

existing = user.query.join(user.spaces).filter(user.username=='bob', space.name=='mainspace').first() print(existing.id) if existing != none:   print('exists') 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -