Writing UserSerializer and UserViewset
Create a Django REST Framework serializer for conversion between Django data structures and Python objects, and implement a viewset for user CRUD operations with proper validation and permissions.
We'll cover the following
A serializer allows us to convert complex Django complex data structures such as QuerySet
or model instances into Python native objects that can be easily converted to JSON
or XML
format. However, a serializer also serializes JSON
or XML
to native Python. Django Rest Framework (DRF) provides a serializers
package we can use to write serializers and validations when API calls are made to an endpoint using this serializer.
Note: Please look at the appendix to see how to install the
djangorestframework
package. We have also addeddjango-filter
for data filtering support.
Let’s add rest_framework
to the INSTALLED_APPS
setting:
Get hands-on with 1400+ tech skills courses.