0

I have written the following cms plugin. With this a user can add a connection from one news entry to a project.

cms_plugins.py:

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool    
class CMSProjectPlugin(CMSPluginBase):
    model = ProjectPlugin
    name = _("Project")
    render_template = "CMSProjectPlugin.html"

    def render(self, context, instance, placeholder):
        context.update({
            'project':instance.project,
            'object':instance,
            'placeholder':placeholder
        })
        return context
plugin_pool.register_plugin(CMSProjectPlugin)

Models:

from django.db import models
from cms.models.fields import PlaceholderField

class Project(models.Model):
    title=models.CharField(_('Title'),max_length=250)
    slug = AutoSlugField(populate_from='title')

class ProjectPlugin(CMSPlugin):
    project = models.ForeignKey(Project)

class NewsEntry(models.Model):
    title=models.CharField(_('Title'),max_length=250)
    content = PlaceholderField('news_content')

How can i get a list of all connected News entries if I do have the project ID? (For backlinks on project detail page)

welworx
  • 370
  • 2
  • 14

1 Answers1

1

This should work:

placeholders = []
for plugin in project.projectplugin_set.all():
    placeholders.append(plugin.placeholder_id)
NewsEntry.objects.filter(content__in=placeholders).distinct()
Community
  • 1
  • 1
digi604
  • 1,080
  • 5
  • 9