我有两个互相拥有外键的资源,例如:
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
?
答案 0 :(得分:1)
根据您在列出时所包含的详细程度,您可以尝试在类别关系上设置full_list=False
,或使用子类别上的full_list
和full_detail
来更改输出。
http://django-tastypie.readthedocs.org/en/latest/fields.html#tastypie.fields.RelatedField.full_list
答案 1 :(得分: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()