1
에 중복 키 오류를보고는 내가 USERPROFILE 클래스가 : 사용자 클래스에 연결되어업데이트 관련/중첩 된 자원 (사용자/사용자 프로필) PATCH
class UserProfile(models.Model):
user = models.OneToOneField(User)
bio = models.CharField(max_length=180, null=True)
.
AUTH_PROFILE_MODULE = 'plantvillage.userprofile'
사용자 정보와 사용자 프로필 세부 정보를 동시에 관리 할 수 있도록 tastypie를 통해 하나의 API를 제공하고 싶습니다. 이 아니라면은 가능하면 두 개의 인터페이스 (하나는 사용자 용, 하나는 userprofiles 용)를 노출하고 싶습니다.
나는 그렇게처럼 내 자원을 설정 :이 오류에
curl --dump-header - -H "Authorization: ApiKey [email protected]:1432ece6a1f34fae24a77315b5c924f756f13807" -H "Content-Type: application/json" -X PATCH --data '{"profile":{"bio":"aquarium"}}' "http://127.0.0.1:8000/api/usr/25/"
결과를 업데이트 그러나
class ProfileResource(ModelResource):
class Meta:
queryset = UserProfile.objects.all()
resource_name = 'profile'
authentication = ApiKeyAuthentication()
authorization = DjangoAuthorization()
allowed_methods = ['get', 'put', 'patch']
class UserResource(ModelResource):
profile = fields.ToOneField(ProfileResource, 'userprofile', full=True)
class Meta:
queryset = User.objects.filter(is_staff=False)
resource_name = 'usr'
authentication = ApiKeyAuthentication()
authorization = DjangoAuthorization()
excludes = ['password', 'is_active', 'is_staff']
, :이 작업을 할 수 있습니다 어떤 변화
"error_message": "duplicate key value violates unique constraint \"plantvillage_userprofile_user_id_key\"\n", "traceback": "Traceback (most recent call last):\n\n File \"/usr/local/lib/python2.6/dist-packages/django_tastypie-0.9.12_alpha-py2.6.egg/tastypie/resources.py\", line 196, in wrapper\n
?