From 8e76a1c6713b649f69f0541b8b72328d1812f9f1 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 17 Oct 2017 15:52:30 +0200 Subject: [PATCH] Set image and title dynamically --- ungleich_page/cms_plugins.py | 14 ++++++++++++-- ungleich_page/models.py | 14 ++++++++++++-- .../glasfaser/section_with_image.html | 7 ++----- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ungleich_page/cms_plugins.py b/ungleich_page/cms_plugins.py index 21c6f8d9..8f2b1883 100644 --- a/ungleich_page/cms_plugins.py +++ b/ungleich_page/cms_plugins.py @@ -1,14 +1,24 @@ +from cms.models.pluginmodel import CMSPlugin from cms.plugin_base import CMSPluginBase from cms.plugin_pool import plugin_pool -from cms.models.pluginmodel import CMSPlugin + +from .models import UngelichPicture @plugin_pool.register_plugin class SectionWithImagePlugin(CMSPluginBase): - model = CMSPlugin + model = UngelichPicture render_template = "ungleich_page/glasfaser/section_with_image.html" cache = False + def render(self, context, instance, placeholder): + context.update({ + 'image': instance.image, + 'object': instance, + 'placeholder': placeholder + }) + return context + @plugin_pool.register_plugin class SectionContact(CMSPluginBase): diff --git a/ungleich_page/models.py b/ungleich_page/models.py index 0b4331b3..4199e6f7 100644 --- a/ungleich_page/models.py +++ b/ungleich_page/models.py @@ -1,3 +1,13 @@ -# from django.db import models +from cms.models.pluginmodel import CMSPlugin +from django.db import models +from filer.fields.image import FilerImageField -# Create your models here. + +class UngelichPicture(CMSPlugin): + image = FilerImageField( + null=True, + blank=True, + related_name="image", + on_delete=models.SET_NULL + ) + title = models.CharField(max_length=200) diff --git a/ungleich_page/templates/ungleich_page/glasfaser/section_with_image.html b/ungleich_page/templates/ungleich_page/glasfaser/section_with_image.html index 0990a3f2..b3477ffe 100644 --- a/ungleich_page/templates/ungleich_page/glasfaser/section_with_image.html +++ b/ungleich_page/templates/ungleich_page/glasfaser/section_with_image.html @@ -1,10 +1,7 @@ -
-
-
-
+
-

TEST TEST

+

{{ object.title }}

\ No newline at end of file