Reputation: 3387
I have an API endpoint which creates an object with a specific field. I do this by using perform_create
def perform_create(self,serializer):
group = DeviceGroup.objects.get(is_default=True, customer_uuid='some uuid')
serializer.save(group_uuid=group)
When I hardcode the uuid of a customer, it works like a charm. However, I obviously do not want to hardcode an uuid in there.
The customer_uuid
is sent in the POST request.
I tried:
self.kwargs['customer_uuid']
self.request.customer_uuid
self.request.GET['customer_uuid']
self.request.GET('customer_uuid')
How do I get the customer_uuid
from the request?
self.request.POST.get('customer_uuid')
does not work when sending JSON in the request.
To fix this, use self.request.data['customer_uuid']
Upvotes: 4
Views: 1132