これが私の設定です:
class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True, related_name="profile")
class UserProfileResource(ModelResource):
class Meta:
queryset = UserProfile.objects.all()
resource_name = 'profile'
authorization = Authorization()
class UserResource(ModelResource):
profile = fields.ToOneField(UserProfileResource, attribute='userprofile', related_name='user', full=True, null=True)
class Meta:
queryset = User.objects.all()
resource_name = 'user'
authorization = Authorization()
list_allowed_methods = ['get', 'post']
ユーザーリソースにPOSTしようとしています:
curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"username":"tata","password":"poooo","profile":{"home_zipcode": "95124"}}' http://192.168.1.103:8000/api/v1/user/
ただし、次のエラーが発生します。
"error_message": "null value in column \"user_id\" violates not-null constraint\