I have custom plugin with the next structure.
models.py looks like
class ProductDescription(models.Model):
name = models.CharField(max_length=30)
icon = models.ImageField(upload_to="installation_image", blank=True, null=True)
description = models.TextField(blank=True, null=True)
def __unicode__(self):
return self.name
class ProductPlugin(CMSPlugin):
product = models.ForeignKey(ProductDescription)
class ProductSpecification(models.Model):
product = models.ForeignKey(ProductDescription)
specification = models.TextField(blank=True, null=True)
class InstallationStep(models.Model):
product = models.ForeignKey(ProductDescription)
step = models.TextField(blank=True, null=True)
image = models.ImageField(upload_to="installation_image", blank=True, null=True)
admin.py
class InstallationStepInline(admin.StackedInline):
model = InstallationStep
extra = 0
class ProductSpecificationInline(admin.StackedInline):
model = ProductSpecification
extra = 0
class DeviceAdmin(admin.ModelAdmin):
inlines = [ProductSpecificationInline ,
InstallationStepInline]
admin.site.register(ProductDescription, DeviceAdmin)
and cms_plugin.py
class CMSProductPlugin(CMSPluginBase):
model = ProductPlugin
name = _("Product Description")
render_template = "product_description.html"
def render(self, context, instance, placeholder):
context.update({
'product':instance.product,
'object':instance,
'placeholder':placeholder
})
return context
plugin_pool.register_plugin(CMSProductPlugin)
So, each product could have none or several specifications and installation steps.
And the question is how can I render those specification and steps in template?
I know how to get data for the ProductDescription class. It is like
<div class="test">{{ product.description }}</div>
but how can I extract other data? i guess it should be something like
{% for steps in product.InstallationStep.all %}
<div class="test">{{ steps.step }}</div>
{% endfor %}
but it does not do anything =(
Thanks in advance!
I think you just need:
Since you have a ForeignKey in the InstallationStep model class, django puts the _set method into the referenced class.
You can experiment with this in the django shell. Templates will fail silently if you try doing foo.bar and there’s no bar in foo…