这是我的设置:
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']
我正在尝试发布到用户资源:
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\