1

我有一个简单的美味派资源:

class EntryResource(ModelResource):
    class Meta:
        queryset = POI.objects.all()
        resource_name = 'poi'

此资源包含一个字段geom,它是一个几何字段。Tastypie 将其输出为 WKT(字符串)。我想将其输出为 geoJSON。

有没有一种简单的方法可以让 EntryResource 输出 attr.json 而不是 attr?

4

1 回答 1

0

在美味派中,您可以在定义具有属性的资源字段时访问字段属性,例如从您可以执行的日期获取一年

class EntryResource(ModelResource):
    year = fields.IntegerField(attribute='modified__year')
    ...

所以你可以试试

attr_json = fields.CharField(attribute='attr__json')
于 2012-02-15T10:36:32.887 回答