Open the api/views.py
file and replace the code for the MessageListResource.get
method with the highlighted lines in the next listing. In addition, make sure that you add the import statement. The code file for the sample is included in the restful_python_chapter_07_01
folder:
from helpers import PaginationHelper
class MessageListResource(Resource):
def get(self):
pagination_helper = PaginationHelper(
request,
query=Message.query,
resource_for_url='api.messagelistresource',
key_name='results',
schema=message_schema)
result = pagination_helper.paginate_query()
return result
The new code for the get
method creates an instance of the previously explained PaginationHelper
class named pagination_helper
with the request
object as the first argument. The named arguments specify the query
, resource_for_url
, key_name
, and schema
that the PaginationHelper
instance has to...