Skip to content Skip to sidebar Skip to footer

Post Related Fields Django Rest Framework

new at django. What I am trying to do is POSTING a model which has a OneToOneField property. How do you POST that? Models.py Article(models.Model): name=models.CharField(max_le

Solution 1:

Finally I was able to solve it. It is only about dictionaries.

Method POST

def  post(self,request,format=None):
    serializer=CharacteristicsSerializer(data=request.data)
    if serializer.is_valid():
        tmp=self.get_article(pk=int(self.request.data['article']))
        serializer.save(article=tmp)
        return Response(serializer.data,status=status.HTTP_201_CREATED)
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

For now that is working, if there is another better way to do it and someone want to share it I'll be thankful

Post a Comment for "Post Related Fields Django Rest Framework"