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在哪裏存儲,以便我只能在此視圖中收集正確的對象,而不是收集所有對象?