Python tastypie:序列项0:应为字符串,找到函数

Python tastypie:序列项0:应为字符串,找到函数,python,django,tastypie,Python,Django,Tastypie,这是我的资源.py。使用此代码,我希望筛选具有某些id的位置: class ActionResource(ModelResource): #place = fields.ManyToManyField('restaurant.resource.PlaceResource', 'place', full=True, null=True) place = fields.ManyToManyField(PlaceResource,

这是我的资源.py。使用此代码,我希望筛选具有某些id的位置:

class ActionResource(ModelResource):
    #place = fields.ManyToManyField('restaurant.resource.PlaceResource', 'place', full=True, null=True)
    place = fields.ManyToManyField(PlaceResource,
                                attribute=lambda bundle: PlaceInfo.objects.filter(action=bundle.obj))

    class Meta:
        queryset = ActionInfo.objects.all()
        resource_name = 'action'

        filtering = {
            'place' : ALL_WITH_RELATIONS,
        }

class PlaceResource(ModelResource):
    location = fields.ManyToManyField(PlaceLocationResource, 'location')
    class Meta:
        queryset = PlaceInfo.objects.all()
        resource_name = 'place'

        filtering = {
            'id' : ALL,
        }
通过action id,我只能找到一个地方,action是uniqe for place。使用此url,我得到一个错误:

http://localhost/api/v1/action/?place__id=2&format=json
Django模型看起来像PlaceModel,它有许多引用ActionModel的字段

sequence item 0: expected string, function found
为我提供了关于位置的普通json

附加:

error: "The model '<ActionInfo: name>' has an empty attribute 'place' and doesn't allow a null value."
我的Django车型:

http://localhost/api/v1/action/2/?format=json
.CASCADE,null=True) action=models.ManyToManyField(ActionInfo,related_name=“action”,blank=True)

我喜欢我必须这样构造我的资源:

class ActionInfo(models.Model):
    name        = models.ForeignKey(ActionName,     related_name="title",    on_delete=models.CASCADE, null=True, blank=True)

class PlaceInfo(models.Model):
    name            = models.ForeignKey(PlaceName, related_name="title", on_delete=models
但有了这样的代码,我得到了:

class ActionResource(ModelResource):
    place   = fields.ToOneField(PlaceResource, 'place')

class PlaceResource(ModelResource):
    location    = fields.ManyToManyField(PlaceLocationResource, 
    action = fields.ToManyField('menus.resources.ActionResource', 'action', full=True)
求解:

error: "The model '<ActionInfo: name>' has an empty attribute 'place' and doesn't allow a null value."
现在,它可以处理:

class ActionResource(ModelResource):
    place   = fields.ToManyField(PlaceResource, 'action', null=True)

尝试将
ActionResource.place.attribute
设置为关系的名称(或反向名称,具体取决于您的型号)

http://localhost/api/v1/action/?place=1&format=json

尝试将
ActionResource.place.attribute
设置为关系的名称(或反向名称,具体取决于您的型号)

http://localhost/api/v1/action/?place=1&format=json