模型
class UserProfile(models.Model):
user = models.OneToOneField(User, primary_key=True)
locations = models.ManyToManyField(Location, verbose_name="Location")
...
DRF观点
class UserProfileView(generics.RetrieveUpdateAPIView):
permission_classes = (IsAuthenticated,)
serializer_class = UserProfileSerializer
def get_object(self, queryset=None):
return UserProfile.objects.get(user=self.request.user)
def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)
DRF网址
url(r'^user/$', UserProfileView.as_view()),
url(r'^user/(?P<pk>[0-9]+)/$', UserProfileView.as_view()),
我的Vue资源:
Vue.http.patch(`${BASE_URL}/user/`, profile)
但是我得到了这样的错误:
ValueError: Cannot assign "3": "UserProfile.user" must be a "User" instance
如何从Vue发布用户实例? (我尝试更新位置字段发送PATCH,如{user:3,locations:[1,2,3]}