2👍
Although this is an old question as I came across the same problem and found the answer I though I’d share it. You should use this line in your serializer:
id = serializers.ReadOnlyField()
👤Amen
1👍
If you use the generic views a “post” function is provided to, and it looks by default like
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs) # A Response object with the data you saved
You could instead return pretty much anything you want:
def post(self, request, *args, **kwargs):
self.create(request, *args, **kwargs)
job = # Fetch the object you just created and serialize it
return Response(job)
- [Django]-Cloud SQL socket open failed with error: No such file or directory
- [Django]-How to delete a record after a certain time of it's creation in Django?
Source:stackexchange.com