Django + backbone + tastypie:处理关系

Gio*_*ner 7 django model foreign-keys backbone.js tastypie

假设我有Django模型的Category和Item,其中Item具有ForeignKey朝向Category(这个字段被命名为category),我在Backbone中创建了Item模型,如下所示:

defaults:{ name:'', category_id:''}
Run Code Online (Sandbox Code Playgroud)

但是当我保存模型一个项目我得到错误:

raise self.field.rel.to.DoesNotExist\n\nDoesNotExist\n

在django/db/models/fields/related.py中,似乎category_id字段不被识别为Item模型的字段.

我正在使用tastyapi,而ItemModel和ItemResource是:

class Item(models.Model):
  id = models.AutoField(primary_key=True)
  category=models.ForeignKey('categories.Category')
  name = models.CharField(max_length=300)

class ProductResource(ModelResource):
  category=fields.ForeignKey(CategoryResource,'category')

class Meta: 
    queryset= Product.objects.all()
    resource_name='product'
    authorization= Authorization()
Run Code Online (Sandbox Code Playgroud)

一些细节:当related.py文件执行val = getattr(instance, self.field.attname)self.field.attname是STORE_ID但isntance.store_id是无,即使骨干模型,为STORE_ID值,26.

一些帮助?