Question

Here are my resources:

class CourseResource(ModelResource):  
    subjects = fields.ToManyField('core.api.SubjectResource', 'subjects', full=True)  
    class Meta:
        queryset = Course.objects.all()  
        resource_name = 'course'  
        authorization = Authorization()   
        validation = FormValidation(form_class=CourseForm) 

class SubjectResource(ModelResource):  
    class Meta:  
        queryset = Subject.objects.all()  
        resource_name = 'subject'  
        authorization = Authorization()  

I am trying to post using curl on a django-tastypie system.

curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"title":"title 123","description":"sdfsadfsdf","created_by":"1","created_on":"2012-02-23 03:24:56","initial-created_on":"2012-02-23 03:24:56.419838","subjects":["/api/v1/subject/1/"]}' http://127.0.0.1:8000/api/v1/course/

This is what i get:

HTTP/1.0 400 BAD REQUEST
Date: Thu, 23 Feb 2012 12:28:15 GMT
Server: WSGIServer/0.1 Python/2.7.2+
Content-Type: application/json; charset=utf-8

{"subjects": ["\"/api/v1/subject/1/\" is not a valid value for a primary key."]}%

I have tried sending just the ids instead of the resource_uri too, but that also doesn't work. I am sure my post data is wrong in some way. How do I fix this?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top