I have the following serializer
class MyModelSerializer(serializers.ModelSerializer):
user = UserSerializer()
def create(self, validated_data):
print("TEST")
MyModel, created = MyModel.objects.get_or_create(**validated_data)
return MyModel
class Meta:
model = MyModel
fields = ('pk', 'title', 'user', 'movie', 'timestamp', 'text',)
and the following viewset:
class MyModelViewSet(viewsets.ModelViewSet):
queryset = MyModel.objects.all()
serializer_class = MyModelSerializer
When I make an POST
request to the endpoint corresponding to specified viewset, the create()
method does absolutely nothing. I tried to print out in console TEST
as you can see, but nothing.
Does anyone have an idea about this strange behavior?
Thanks in advace!
Edit: API call:
return axios({
method: 'post',
url: 'http://localhost:8000/api/mymodel/',
data: {
title: this.title,
movie: this.id,
text: this.text,
user: this.user
}