-1
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

davidism
  • 121,510
  • 29
  • 395
  • 339
  • 1
    And what is your error? Or you don't have an error, but results are not what you expected? For me the problem is not clear. Provide your sqlalchemy model and example query arguments values. – jorzel Jan 14 '22 at 07:34
  • filter() got an unexpected keyword argument 'university' but i have the field university on my model – saugat timsina Jan 14 '22 at 09:27

1 Answers1

1

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

jorzel
  • 1,216
  • 1
  • 8
  • 12