I would like to get JSON data on my backend without tying it to a model. For example, in json data like this I want access to quantity
but don't want it tied to any model.
{
"email": "some@gmail.com"
"quantity": 5,
"profile": {
"telephone_number": "333333333"
}
}
My serializer:
class PaymentSerializer (serializers.ModelSerializer):
profile = UserProfilePaymentSerializer()
# subscription = UserSubscriptionSerializer()
class Meta:
model = User
fields = ('email', 'profile',)
def create(self, validated_data):
profile_data = validated_data.pop('profile')
user = AuthUser.objects.create(**validated_data)
Profile.objects.create(user=user, **profile_data)
return user
def update (self, instance, validated_data):
instance.quantity = validated_data.get('quantity', instance.quantity)
print instance.quantity
return instance
When I send a PATCH request, I get an error
'User' object has no attribute 'quantity'