So far, our RESTful API has performed CRUD operations on a single database table. Now, we want to create a more complex RESTful API with Django REST Framework to interact with a complex database model that has to allow us to register player scores for played games that are grouped into game categories. In our previous RESTful API, we used a string field to specify the game category for a game. In this case, we want to be able to easily retrieve all the games that belong to a specific game category, and therefore, we will have a relationship between a game and a game category.
We should be able to perform CRUD operations on different related resources and resource collections. The following list enumerates the resources and the model names that we will use to represent them in Django REST Framework:
GameCategory
model)Game
model)Player
model)PlayerScore
model)The game category (GameCategory
) just requires a name, and we need the following data for a game (Game
):
GameCategory
)We need the following data for a player (Player
):
We need the following data for the score achieved by a player (PlayerScore
):
Player
)Game
)We will take advantage of all the resources and their relationships to analyze different options that Django REST Framework provides us when working with related resources. Instead of building an API that uses the same configuration to display related resources, we will use diverse configurations that will allow us to select the most appropriate options based on the particular requirements of the APIs that we are developing.
3.143.205.27