serializers.py
class MovieSerializer(serializers.ModelSerializer):
class Meta:
model = Movie
fields = [
\'popular
Override the create()
method of the serializer as below,
class MovieSerializer(serializers.ModelSerializer):
genre = serializers.ListSerializer(child=serializers.CharField())
class Meta:
model = Movie
fields = [
'popularity',
'director',
'genre',
'imdb_score',
'name',
]
def create(self, validated_data):
genre = validated_data.pop('genre',[])
movie = super().create(validated_data)
genre_qs = Genre.objects.filter(name__in=genre)
movie.genre.add(*genre_qs)
return movie