I have written a carousel plugin for Django-CMS which displays screenshots. The underlying model has some carousel-related parameters (height, animation style etc), and a ForeignKey
to ScreenshotGroup
:
class ScreenshotGroup(models.Model):
name = models.CharField(max_length=60)
screenshots = models.ManyToManyField(Screenshot, through="ScreenshotGroupMember")
class Screenshot(models.Model):
name = models.CharField(max_length=60)
desc = models.TextField(_("description"), blank=True)
img = models.ImageField(upload_to='img/')
class CarouselPluginModel(CMSPlugin):
group = models.ForeignKey(ScreenshotGroup)
height = models.IntegerField()
...
The carousel's view method contains:
context['item_list'] = instance.group.screenshots.all()
(Actually since I'm using Django-CMS, it's in the cms_plugins.py
render
method, not a view
method.)
The template refers to the screenshot fields via:
{% for item in item_list %}
{{ item.name }}
{{ item.desc }}
...{{ item.img }}...
{% endfor %}
My question is: I want to generalise my carousel plugin to reuse it in other projects, so that does not depend on the Screenshot
model. I can replace the contents of the template's for
loop with an include
to allow each project to specify how to display the item in a carousel. But how do I generalise the CarouselPluginModel
's ForeignKey
?
In any particular application, I only want one type of model allowed (ScreenshotGroup
in my example) - I don't want the admin console to allow any other models to be included.
Thanks!