Activity 12.01 – creating an API endpoint for a top contributors page
Imagine that your team decides to create a web page that displays the top contributors (authors, coauthors, and editors) in your database. They decide to enlist the services of an external developer to create an app in ReactJS. To integrate with the Django backend, the developer will need an endpoint that provides the following:
- A list of all contributors in the database
- For each contributor, a list of all books they contributed to
- For each contributor, the number of books they contributed to
- For each book they contributed to, their role in the book
The final API view should look like this:
Figure 12.4: The top contributors endpoint
To perform this task, execute the following steps:
- Add a method to the
Contributor
class that returns the number of contributions made. - Add
ContributionSerializer
, which serializes theBookContribution
model...