我刚刚使用DRF为我的项目安装了django-cities-light,但我无法让它工作。
我的用户模型将城市和国家字段定义为外键,这是我试图获取用户时得到的结果:
Could not resolve URL for hyperlinked relationship using view name "city-detail".
You may have failed to include the related model in your API, or incorrectly configured the lookup_field attribute on this field.有什么想法吗?
谢谢!
发布于 2015-02-06 06:20:21
使用django-cities-light和Rest Framework3,你需要使用他们提供的view_name:
cities-light-api-{model}-detail
class FooSerializer(HyperlinkedModelSerializer):
url = relations.HyperlinkedIdentityField(view_name="foo-detail")
city = relations.HyperlinkedRelatedField(
view_name="cities-light-api-city-detail", queryset=City.objects.all(),
)
class Meta:
model = Foo
read_only_fields = ('id',)https://stackoverflow.com/questions/27111006
复制相似问题