在django-cms中保存插件时复制model-objects



我开始使用django-cms,遇到了一些问题。

第一个问题:

当我用我的插件(CMSServicesListPlugin)保存页面时,在管理端我看到了相关对象的副本。他们有相同的身份。如何隐藏副本或更好地如何禁用创建副本

第二个问题:

当我将ForeignKey-field插件更改为cms.Page (CMSBannerWithImagePlugin)时,我看到选择页面的副本。如何解决这个问题?

我的模型:

# models.py
class Service(models.Model):
    title =             models.CharField(blank=False, null=False, max_length=255)
class ServicePluginRelation(models.Model):
    service =           models.ForeignKey('services.Service', blank=False, null=False, related_name='relations')
    plugin =            models.ForeignKey('services.ServicesListPlugin', blank=False, null=False, related_name='relations')
class ServicesListPlugin(CMSPlugin):
    title =             models.CharField(blank=True, null=True, max_length=255)
    services =          models.ManyToManyField('services.Service', related_name='plugins', blank=False, null=False, through=ServicePluginRelation)
    def copy_relations(self, oldinstance):
        for relation in oldinstance.relations.all() :
            relation.plugin = self
            relation.pk = None
            relation.id = None
            relation.save()
class BannerWithImage(CMSPlugin):
    image =         models.ImageField(blank=True, null=True, upload_to='links/link_with_image/image')    
    page =          models.ForeignKey('cms.Page', blank=False, null=False)

和普金:

# cms_plugins.py
class ServicePluginRelationInlineAdmin(SortableTabularInline):
    model = ServicePluginRelation
class CMSServicesListPlugin(CMSPluginBase):
    model =     ServicesListPlugin    
    inlines = (ServicePluginRelationInlineAdmin,)
    def get_render_template(self, context, instance, placeholder):
        return 'services/services_list.html'
class CMSBannerWithImagePlugin(CMSPluginBase):
    model =     BannerWithImage
    render_template =   'links/link_with_image.html'

谢谢!

对于刚接触CMS的人来说,这是一个常见的误解。

一旦你发布了一个页面,它的副本&所有附加的东西(插件等)都是作为"实时"版本创建的。

然后你可以对页面进行编辑,这些编辑保存在页面的草稿版本中,附带插件的草稿版本等。一旦该草案版本发布,一个新的副本将取代旧的实时版本。看一下发布文档

不要担心这个&不要将插件模型暴露给管理员,因为它们应该通过CMS前端进行编辑。

最新更新