0
我最近第一次使用django cms,并且已经创建了一个图库插件来上传图片。django cms和自定义插件模型之间有什么关系?
这是一个非常简单的插件,使用ImageGalleryPlugin
模型,从CMSPluginBase
继承,然后一个Image
模型具有ForeignKey
的画廊。
使用占位符将图库插件附加到页面上,然后查看图库中的图像我已创建apphook
以将插件模板链接到类似于;
def detail(request, page_id=None, gallery_id=None):
"""
View to display all the images in a chosen gallery
and also provide links to the other galleries from the page
"""
gallery = get_object_or_404(ImageGalleryPlugin, pk=gallery_id)
# Then get all the other galleries to allow linking to those
# from within a gallery
more_galleries = ImageGalleryPlugin.objects.all().exclude(pk=gallery.id)
images = gallery.images_set.all()
context = RequestContext(request.context, {
'images': images,
'gallery': gallery,
'more_galleries': more_galleries
})
return render_to_template('gallery-page.html', context)
现在我有这个方法的问题是,当你在CMS发布一个网页它复制所有ImageGalleryPlugin
对象在该网页上,所以当我查看图像,我已经得到了两倍多链接到其他画廊,因为查询收集重复的对象。
我无法正确理解文档中的这种行为,但我认为CMS会保留您创建的原始对象,然后将重复项创建为“实时”版画廊以向用户显示。
在CMS中发生这种情况,我的ImageGalleryPlugin
对象的ID在哪里存储,以便我只能在此视图中收集正确的对象,而不是收集所有对象?