0

我有 2 个相互具有外键的资源,例如:

class GroupResource(ModelResource):
    categories = fields.ToManyField(CategoryResource, 'category_set', 'categories', full=True)

    class Meta:
        queryset = Group.objects.all()


class CategoryResource(ModelResource):
    subcategories = fields.ToManyField(SubcategoryResource, 'subcategory_set', 'subcategories', full=True)

    class Meta:
        queryset = Category.objects.all()

当我列出它时,GroupResource它也会列出subcategories. 我怎样才能防止这种情况,只列出categories而不是subcategories

4

2 回答 2

1

根据您希望列出时包含的详细程度,您可以尝试设置full_list=False类别关系或使用full_listfull_detail子类别来更改输出。

http://django-tastypie.readthedocs.org/en/latest/fields.html#tastypie.fields.RelatedField.full_list

于 2013-06-26T00:15:00.433 回答
0

只需添加use_in='list'到子类别中Category

class CategoryResource(ModelResource):
  subcategories = fields.ToManyField(SubcategoryResource, 'subcategory_set', 'subcategories', full=True, use_in='list')

  class Meta:
    queryset = Category.objects.all()
于 2013-06-26T12:30:37.763 回答