Search⌘ K
AI Features

Listing and Retrieving Users

Explore how to create user serializers and API views to list all users and retrieve specific user details. Understand setting up endpoints and testing them for managing user data in Django RESTful.

User serializer

When we want to fetch user objects from the database, this serializer class takes care of the serialization of those user objects. Let’s create the user serializer class in serializers.py, as shown below.

Python 3.8
# .. other serializers
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ["id","email","is_active","is_staff"]

In the code above:

  • The UserSerializer class inherits from ModelSerializer so it can map the model fields into this serializer.
  • In the Meta class, the User
...