I'm trying to add TastyPie
to my Django
project to build a RESTful API. I'm using Django 1.8.2
. I'm following the official tutorial.
I created a resource:
# myapp/api.py
from tastypie.resources import ModelResource
from myapp.models import Entry
class RecipeResource(ModelResource):
class Meta:
queryset = Entry.objects.all()
# urls.py
from django.conf.urls import include, url
from django.contrib import admin
from myapp.api import RecipeResource
recipe_resource = RecipeResource()
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include(recipe_resource.urls)),
]
I don't think the problem is in my code since it's pretty much a copy & paste from the tutorial. Error occurs when the import is executed:
from myapp.api import RecipeResource
I am new to Django and TastyPie. Might it be that the TastyPie does not work with Django 1.8.2?
The error:
File "/Users/rafalsroka/Documents/Pthn/Recipes/recipes-backend/lib/python2.7/site-packages/tastypie/resources.py", line 1740, in <module>
class BaseModelResource(Resource):
File "/Users/rafalsroka/Documents/Pthn/Recipes/recipes-backend/lib/python2.7/site-packages/tastypie/resources.py", line 2210, in BaseModelResource
@transaction.commit_on_success()
AttributeError: 'module' object has no attribute 'commit_on_success'
It looks like that it is TastyPie
lacking the support for Django 1.8.2
.
The commit_on_success
has been removed in this version of Django
.
I wanted to use the latest release so I switched to Django Rest Framework.