tastypie - Post request to create new custom users in Django -
i have model extend user model:
class readeruser(models.model): user = models.onetoonefield(user) email = models.emailfield() def __unicode__(self): return self.user.first_name + ',' + str(self.email)
i create resources tastypie 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()
when try create new user creatin post request, using curl, got following:
->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"}
what doing wrong? try have setup simple possible. know issue coming onetoonefield keyword, don't know how fix. checked many different solutions , didn't find working me.
any hints?
your data needs contain user
you'd attach readeruser
to.
if remember correctly, should submit full object representation of user, returned if did e.g.: curl http://localhost:8000/api/user/1
curl --dump-header - -h "content-type: application/json" -x post --data '{"email": "test@test.com", "password": "", "user": {"blah"}}' http://localhost:8000/api/newuser
if don't have user
though, you'll need create 1 first. can of course api call.
Comments
Post a Comment