class DeviceResource(ModelResource):
class Meta :
queryset = Device.objects.all()
resource_name='device'
class UpdateResource(ModelResource):
device = fields.ForeignKey(DeviceResource, attribute='device',full=True, null=True)
class Meta :
queryset = Update.objects.all()
resource_name = 'update'
filtering = {'imei' : ALL }
更新模型有一個字段「IMEI」,它映射到「IMEI」在設備與ForeignKey的Tastypie |當Django的ForeignKey的使用「to_field」和相關資源不是主鍵
我想會有一些屬性to_field與我可以寫
device = fields.ForeignKey(DeviceResource, to_field='imei'attribute='device',full=True, null=True)
但有沒有這樣的事情在tastypie
這裏是我的設備和更新型號
你檢查RELATED_FIELD參數(在ressources)和[ related_name](http://django-tastypie.readthedocs.org/en/latest/fields.html#related-name)(在模型中)? – nnaelle
@nnaelle對不起,我沒有完全讓你。我做了這個'device = fields.ForeignKey(DeviceResource,attribute ='device',related_name ='imei',full = True,null = True)''和'device = fields.ForeignKey(DeviceResource,attribute ='device',related_field ='imei',full = True,null = True)',這不起作用 – ZenOut