0

簡単な問題。TastyPie でモデルの属性として「format」という名前があるとどうなりますか?

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,
        }
4

1 に答える 1