假设我有这些模型(显然省略了一些属性):
class Product(Model):
name = CharField(max_length=100)
class Variety(Model):
product = ForeignKey(Product)
class ProductMerge(Model):
parent_product = ForeignKey(Product)
products = ManyToManyField(Product, related_name='merge_proposals')
如何在管理面板的内联中显示所有Product
的ProductMerge
变体
我尝试在TabularInline
上设置自定义get_queryset
:
def get_queryset(self, request):
return Variety.objects.filter(
product__in=self.instance.parent.child_products.all())
但我有以下例外:
ValueError: 'marketplace.Variety' has no ForeignKey to 'marketplace.ProductMerge'.
目前没有回答
相关问题 更多 >
编程相关推荐