简单的问题。当您将名称“格式”作为 TastyPie 模型的属性时会发生什么?
http://0.0.0.0:9000/api/v1/library_type/?format=json?
当你有一个看起来像这样的模型时,你如何处理查询。
class LibraryType(models.Model):
"""The information about each library type."""
format = models.IntegerField(choices=LIBRARYTYPE_CHOICES)
equiv = models.IntegerField()
name = models.CharField(max_length=96)
prefix = models.CharField(max_length=96)
description = models.CharField(max_length=255, db_column='remark')
你最终得到:
{
"error": "Invalid resource lookup data provided (mismatched type)."
}
显然这是有道理的,但你如何使用它呢?相应的资源定义。
class LibraryTypeResource(ModelResource):
class Meta:
queryset = LibraryType.objects.all()
resource_name = 'library_type'
list_allowed_methods = ['get',]
detail_allowed_methods = ['get', ]
filtering = {
'id': ('exact', ),
'name': ALL,
'format': ALL,
'prefix': ALL,
'description': ALL,
'site': ALL_WITH_RELATIONS,
}