Am facing a problem with configuring piston for django, every time I specify the model name it runs I get the below error
RuntimeError at /en/vehicle/api/car.json
Circular reference detected while emitting response
Request Method: GET
Request URL: http://127.0.0.1:8000/en/vehicle/api/car.json
Django Version: 1.4.1
Exception Type: RuntimeError
Exception Value:
Circular reference detected while emitting response
Exception Location: /Users/mo/Projects/pythonic/gar-env/lib/python2.7/site-packages/piston/emitters.py in _any, line 109
Python Executable: /Users/mo/Projects/pythonic/gar-env/bin/python
Below is my handelrs.py
from piston.handler import BaseHandler
from piston.utils import rc, throttle, translate_mime
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from django.core.urlresolvers import reverse
from django.db.models.loading import get_model
from models import (ModelLookUpI18n as ModelLookup, Image)
from forms import CarForm, ModelLookUpForm, ModelLookUpI18nForm
from django.http import HttpResponse
import logging, json, os
from piston.utils import validate
from django.conf import settings
from django.utils.translation import ugettext as _
class CarHandler(BaseHandler):
"""
CarHandler
"""
allowed_methods = ('GET', 'POST', 'PUT', 'DELETE')
model = Car
fields = ('id', 'model', 'description', 'primary_image', 'color', 'mileage', 'view_count', 'asking_price')
def read(self, request):
params = dict()
params.update({'status' : self.model.STATUS_ACTIVE})
return self.model.objects.filter(**params).order_by('created_at')
in the url.py here is my code
from django.conf.urls import *
from handlers import CarHandler
from piston.resource import Resource
car_resource = Resource(CarHandler)
# API URL schema
urlpatterns += patterns('',
# car API
url(r'^api/car\.(?P<emitter_format>.+)', car_resource, name='vehicle-api-car'),
)
The error is coming at run time, I cannot find a solution to the problem. I tried to remove model and fields attribute from CarHandler class that would make it work. I tired to use get_model and load at run time but again, I would get the same runtime error.
Please advise?