Tjorriemorrie
Tjorriemorrie

Reputation: 17282

Boolean field query with sqlalchemy

Postgres model:

class Song(db.Model):
    id3_parsed = db.Column(db.Boolean, server_default=u'false')

Running the following query gives the correct count:

select count(*) from song where id3_parsed is false;

But how do I do it with flask-sqlalchemy? This doesn't work:

songs = Song.query.filter(Song.id3_parsed == False).all()

Upvotes: 16

Views: 22274

Answers (2)

Aditi Gupta
Aditi Gupta

Reputation: 966

Your query seems to be right, looks like this is flake8 issue.

And that you can ignore by adding # noqa in the line you wrote.

Upvotes: 2

Tjorriemorrie
Tjorriemorrie

Reputation: 17282

songs = Song.query.filter(Song.id3_parsed.is_(False)).all()

Upvotes: 49

Related Questions