OMY
OMY

Reputation: 412

Django tastypie overriding obj_create won't work

I am trying to use tastypie in my django application so that I only use Ajax to get the data.

But I stumbled upon something strange, when overriding obj_create() nothing saves if I call super, I have to write the code myself, any one has any idea?

def obj_create(self, bundle, request = None, **kwargs):
    return super(MyResource, self).obj_create(bundle, request, kwargs);

This is the simplest form that I had. There's no error and the code works, BUT nothing is saved in DB. If I remove these lines in my code, it works as intended.

Anyone knows why this happens?

p.s: My resource is defined like MyResource(ModelResource): and I have allowed Post in my Meta p.s2: I am using python 2.7.6, django 1.6.5, tastypie 0.11.1

Upvotes: 1

Views: 113

Answers (1)

Tomasz Jakub Rup
Tomasz Jakub Rup

Reputation: 10680

Simple typo. Missing ** before kwargs:

def obj_create(self, bundle, request=None, **kwargs):
    return super(MyResource, self).obj_create(bundle, request, **kwargs)

Upvotes: 1

Related Questions