简体   繁体   English

如何在django管理员的编辑页面中添加“预览”按钮?

[英]How can i add a 'preview' button in the edit page of the django admin?

After long searches, I still didn't find any answers I've been able to apply. 经过长时间的搜索,我仍然没有找到任何我能够应用的答案。

I have in my django app a models which creates new pages in the website: 我在我的django应用程序中有一个模型,可以在网站上创建新页面:

class Page(models.Model):
    name = models.CharField(max_length=255, null=False, blank=False, unique=True)
    content = HTMLField('Content')
    slug = models.CharField(max_length=255)
    background_image = models.ImageField(
        upload_to="page_background/",
        null=False,
        blank=False,
        default="default/livresse_logo.png",
    )

As you can see there's a WYSIWYG editor in it, a title and a background image. 正如你所看到的,里面有一个WYSIWYG编辑器,一个标题和一个背景图像。

When I go to the admin page it's like this: 当我进入管理页面时,它是这样的:

在此输入图像描述

I'm looking for a way to add a button 'preview' (maybe next to the save button) that would show the content of my model included in the template that will be use to display the page before saving. 我正在寻找一种方法来添加按钮'预览'(可能在保存按钮旁边),该按钮将显示模板中包含的模型内容,用于在保存之前显示页面。 I'd like this button only displaying for that model. 我想这个按钮只显示该模型。 Hope i'm clear enough. 希望我足够清楚。

我不确定是否有一个优雅的解决方案,但你可以稍微改变一下你的问题,在模型中实现布尔参数is_published,并以这样的方式编写视图,使得只有尚未发布的文章才被看到由超级用户,所以我通常组织预览。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM