我有两个插件ProductSelector(parent)和SpecificationSelector(child)。我想设置子级,以便当您将其添加到父级时,所显示的规范是产品(父级)的唯一规范。现在它从表格中提取了所有的规格。这些行允许我过滤数据以得到我想要的。在
编辑:我发现了一个我在代码中修复的错误。我把PluginBase的名字和模型的名字一样。这让我可以产品选择器.objects.get(cmsplugin-u-ptr)=实例.父级)以获取父实例。我仍然需要弄清楚如何将过滤后的规范列表传递到“PluginAdmin接口”
product = ProductSelector.objects.get(cmsplugin_ptr=instance.parent)
specification = Specifications.objects.filter(product_name__product_name__iexact = product.product_name)
但是,我还没有弄清楚如何将过滤后的列表发送到插件管理接口。在
^{pr2}$在模型.py在
class ProductSelector(CMSPlugin):
product_name = models.ForeignKey(Product, help_text = "Select the product you want to place")
new_product = models.BooleanField(blank=True)
class SpecificationSelector(CMSPlugin):
specification = models.ManyToManyField(Specifications, blank=True)
def __unicode__(self):
return unicode(self.specification)
这是占位符中Django cms插件的屏幕截图。目前它显示了表中的所有规格,但我只希望它是特定产品的规格。在
提前谢谢你的帮助。在
CMSPluginBase
来自ModelAdmin
,这意味着您可以在添加和编辑插件时重写呈现的表单。在因此您可以创建一个
ModelForm
子类,如下所示:然后将您的
^{pr2}$SpecificationSelectorPlugin
改为如下形式:只有当规范插件是产品插件的直接子级时,上述方法才有效。在
相关问题 更多 >
编程相关推荐