I have 3 connected models: User -> UserProfile -> BuyerProfile, and when a user makes an account, I want a User to be made, then a UserProfile, then a BuyerProfile. I'm using a ModelSerializer, but when I use the browsable api and make a post, I get:
{
"userprofile": {
"user": [
"This field is required."
]
}
}
Any ideas on how to do this?
class BuyerProfileViewSet(viewsets.ModelViewSet):
queryset = BuyerProfile.objects.all()
serializer_class = BuyerProfileSerializer
Serializers:
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ('username',)
class UserProfileSerializer(serializers.HyperlinkedModelSerializer):
user = UserSerializer()
class Meta:
model = UserProfile
fields = ('user', 'bio','prof_type')
class BuyerProfileSerializer(serializers.HyperlinkedModelSerializer):
userprofile = UserProfileSerializer()
class Meta:
model = BuyerProfile
fields = ('userprofile', 'company','sitename')