I'm providing JSON to a view like so -
{
"username": "name",
"first_name": "john",
"last_name": "doe",
"email": "[email protected]",
"profile": {
"company": "abc corp"
}
}
I'm then passing it into the following view to post -
def post(self, request, format=None):
uuid = generate_uuid(request.data.get('username'))
data = {'username': request.data.get('username'),
'first_name': request.data.get('first_name'),
'last_name': request.data.get('last_name'),
'email': request.data.get('email'),
'company': request.data.get('profile').('company'),
'uuid': str(uuid)}
serializer = UserSerializer(data=data)
if serializer.is_valid():
print serializer.data
# serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
I'm having difficulty in understanding how to structure the data to maintain the nested value as you can see I'm also including a field for a uuid which will also be in the nested profile object.
These are then being passed into my serializer here -
class UserSerializer(serializers.ModelSerializer):
profile = UserProfileSerializer()
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'profile')
My view currently as it is gives a syntax error on this line -
'company': request.data.get('profile').('company'),
I know it's wrong just not sure how it should be structured.