django活塞在使用模型时发出响应时检测到圆形参考

时间:2012-11-04 15:19:44

标签: django django-piston

我遇到为django配置活塞的问题,每次我指定它运行的模型名称时我都会得到以下错误

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

以下是我的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')
url.py中的

是我的代码

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'),
)

错误是在运行时发生的,我无法找到问题的解决方案。我试图从CarHandler类中删除可以使其工作的模型和字段属性。我厌倦了在运行时使用get_model并加载,但是我会得到相同的运行时错误。

请指教?

1 个答案:

答案 0 :(得分:0)

'model'是外键引用吗?是否有可能Piston在输出中包含'model',它本身可能会引用它所包含的Car模型?