Defining hyperlinks with serializers.HyperlinkedModelSerializer

Now, add the following code to the file to declare the DroneSerializer class. The code file for the sample is included in the hillar_django_restful_06_01 folder in the restful01/drones/ file:

class DroneSerializer(serializers.HyperlinkedModelSerializer): 
    # Display the category name 
    drone_category = serializers.SlugRelatedField(queryset=DroneCategory.objects.all(), slug_field='name') 
    class Meta: 
        model = Drone 
        fields = ( 

The DroneSerializer class is a subclass of the HyperlinkedModelSerializer class. The DroneSerializer class declares a drone_category attribute ...

Get Django RESTful Web Services now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.