Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'BaseQuery' object is not callable Flask [duplicate]

I am getting this error:

TypeError: 'BaseQuery' object is not callable

Here is my code:

companies = Company.query.all()
return Company.query(func.count(Company.id))

I need to find out number of rows in Company model. Please help!

like image 762
Rohit Dhiman Avatar asked Aug 05 '13 12:08

Rohit Dhiman


1 Answers

Company.query isnt callable there. If you've already selected all your companies with companies = Company.query.all(), why not simply use len(companies)?

If you dont want/need to retrieve the data, you can get just the count with Company.query.count()

like image 74
DazWorrall Avatar answered Nov 11 '22 23:11

DazWorrall