我正在我的 sweetpie api 中设置相关字段。
我的 api.py 文件中有这个:
class PeopleResource(ModelResource):
event_id = fields.ForeignKey(EventResource,'event', full=True)
answer_link = fields.ForeignKey(DatePeopleResource,'datepeople', full=True, related_name='datepeople')
class Meta:
queryset = EventPeople.objects.all()
resource_name = 'people'
filtering = {
'event_id' : ALL,
'phone_number' : ALL,
'name' : ALL,
'answer' : ALL,
}
authorization = Authorization()
class DatePeopleResource(ModelResource):
event = fields.ForeignKey(EventResource,'event')
event_date = fields.ForeignKey(DateResource,'event_date')
event_person = fields.ForeignKey(PeopleResource,'event_person', related_name='people')
class Meta:
queryset = DatePeople.objects.all()
resource_name = 'datepeople'
filtering = {
'event' : ALL,
'event_person' : ALL,
'event_date' : ALL,
}
authorization = Authorization()
我的问题是与 PeopleResource 相关的 DatePeopleResource 字段有效,但第一个无效。(PeopleResource中与DatePeopleResource相关的一项)
我猜这是因为 DatePeopleResource 尚未定义。在美味的文档中,看起来我必须在调用 DatePeopleResource 之前添加 path.to.api.resource,如下所示:
answer_link = fields.ForeignKey(path.to.resource.DatePeopleResource,'datepeople', full=True, related_name='datepeople')
但我不知道路径是什么!我试过'resources','api'......我不太明白这条路是什么。
谢谢你的帮助,我卡住了!