Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango: how to create object with Tastypie
    primarykey
    data
    text
    <p>I have a threaded mptt comments model to use with my BlogItem model:</p> <pre><code>class MyComment(MPTTModel, Comment): parent = TreeForeignKey('self', null=True, blank=True, related_name='children') class MPTTMeta: order_insertion_by=['-submit_date'] class Meta: ordering=['tree_id','lft'] </code></pre> <p>For tastypie i made Resource</p> <pre><code>class MyCommentResource(ModelResource): # i tried to use this commented strings (and of course i created related resources) #comment = fields.ForeignKey(CommentRosource, 'comment', null=True, full=True) #site = fields.ForeignKey(SiteResource, 'site', null=True, full=True) #content_type = fields.ForeignKey(ContentTypeResource, 'content_type', null=True, full=True) #children = fields.ToManyField('self', 'children', null=True, full=True) #content_object = GenericForeignKeyField({BlogItem: BlogItemResource}, 'content_object', null=True, full=True) class Meta: queryset = MyComment.objects.filter(level=0) resource_name = 'myComment' include_resource_uri = False allowed_methods = ['get', 'post', 'put'] include_resource_uri = False filtering = { 'object_pk': ALL, 'level': ALL } authorization= Authorization() </code></pre> <p>After that i have working api for GET requests fo MyComment model (i can see all comments (commenter's name, comment text, mptt level, pagination etc)</p> <p>But when i try to make curl (or js) erquest:</p> <pre><code>curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"comment":"sdfsdfsdf"}' http://myhostname.com:80/api/v1/myComment/ &gt; /tmp/err.html </code></pre> <p>I get error "current transaction is aborted, commands ignored until end of transaction block" or other errors ("DoesNotExist at /api/v1/myComment/ No exception supplied", "Cannot assign None: "MyComment.content_type" does not allow null values." - but in request i POST {"content_type":{"id":"15"}} or link to content_type in my api that also works great).</p> <p>For other, more simpler models (without generic relation, but with ForeignKeys) i can make curl requests and get "201 created" response, so i think i have error related to "generic" comments model</p> <p>I'm doing wrong? Is there any docs or manuals - how to create object for "generic" model via tastypie?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload