[Answer]-Djangorestframework :type object has no attribute 'id'

1๐Ÿ‘

โœ…

A HyperlinkedRelatedField must have a source that points at a related object on the model. You are looking for a HyperlinkedIdentityField, which will give a link for the current object, similar to what a HyperlinkedModelSerializer will do automatically for you.

class MovieSerializer(serializers.ModelSerializer): 
    link = serializers.HyperlinkedIdentityField(view_name='movie_detail')

    class Meta:
        model = Movie
        fields = ( 'link', 'title', )

Leave a comment