8: Pagination, Searching, and Ordering
Activity 13: Implementing Pagination on the User-Specific Recipe Retrieval API
Solution
- Modify the code in the
get_all_by_user
method undermodels/recipe.py
, as follows:@classmethod def get_all_by_user(cls, user_id, page, per_page, visibility='public'): query = cls.query.filter_by(user_id=user_id) if visibility == 'public': query = cls.query.filter_by(user_id=user_id, is_publish=True) elif visibility == 'private': query = cls.query.filter_by(user_id=user_id, is_publish=False) return query.order_by(desc(cls.created_at)).paginate...