flasksqlalchemy query multiple parameter with startwith and paginate
i am trying to query multiple parameter with startswith and other parameter and pagination in flask.
results_of_search = Course.query.filter(Course.title.startswith(search_data)).paginate(per_page=9)
this query is giving me the correct result but i want to add other filters as well
results_of_search = Course.query.filter(Course.title.startswith(search_data),university=current_user.uni).paginate(per_page=9)
i have tried searching everywhere
You mixed syntax of filter
and filter_by
methods. For filter
method there should be also model name before attribute name, and you should use ==
, instead od =
:
Course.query.filter(
Course.title.startswith(search_data),
Course.university == current_user.uni
).paginate(per_page=9)
Here is a topic about differences between filter
and filter_by
: Difference between filter and filter_by in SQLAlchemy