我有一个模型,我在其中扩展了用户模型:
class ReaderUser(models.Model):
        user = models.OneToOneField(User)
        email = models.EmailField()                                                                     
        def __unicode__(self):                                                                          
          return self.user.first_name + ',' + str(self.email)
我还为我的美味派 API 创建了资源:
class CreateReaderUserResource(ModelResource):
    user = fields.OneToOneField('UserResource', 'user', full=False)                                 
    class Meta:
        allowed_methods = ['post']                                                                  
        always_return_data = True
        authentication = Authentication()                                                           
        authorization = Authorization()                                                             
        queryset = ReaderUser.objects.all()                                                         
        resource_name = 'newuser'
class ReaderUserResource(ModelResource):
    class Meta:
        queryset = ReaderUser.objects.all()
        allowed_methods = ['get, put, patch']
        resource_name = 'ruser'                                                                     
class UserResource(ModelResource):                                                                  
    raw_password = fields.CharField(attribute=None, readonly=True, null=True,                       
                                      blank=True)                                                     
    class Meta:
        authentication = MultiAuthentication(
            BasicAuthentication(),
            ApiKeyAuthentication())
        authorization = Authorization()
        allowed_methods = ['get', 'patch', 'put']
        always_return_data = True
        queryset = User.objects.all()
当我尝试通过使用 curl 创建 POST 请求来创建新用户时,我得到以下信息:
 ->curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"email": "test@test.com", "password": "groscaca"}' http://localhost:8000/api/newuser/
HTTP/1.0 404 NOT FOUND
Date: Tue, 03 Sep 2013 21:17:28 GMT
Server: WSGIServer/0.1 Python/2.7.1
Content-Type: application/json
\"/Users/jrm/Documents/Perso/simplereader/env/lib/python2.7/site-packages/django/db/models/fields/related.py\", line 389, in __get__\n    
raise self.field.rel.to.DoesNotExist\n\nDoesNotExist\n"}
我究竟做错了什么?我尝试让设置尽可能简单。我知道问题来自 OneToOneField 关键字,但我不知道如何解决。我检查了许多不同的解决方案,但没有找到任何适合我的解决方案。
有什么提示吗?