当前位置:网站首页>Message mechanism of dtcloud (3)
Message mechanism of dtcloud (3)
2022-07-16 09:00:00 【Jiang Zhenjian 15954039008】
7、 ... and 、 Website visibility
You can easily control which pages on the website ( Record ) so , Which are not visible , Release function .
To achieve this function , The code is as follows :
class BlogPost(models.Model):
_name = "blog.post"
_description = "Blog Post"
_inherit = ['website.published.mixin']
This mixin Add two fields to the model :
website_published: Boolean field indicating the publishing status
website_url: Char Field , Represents the URL
it is to be noted that website_urel It is a calculation type field , And must be included in the class :
def _compute_website_url(self):
for blog_post in self:
blog_post.website_url = "/blog/%s" % (log_post.blog_id)
Once the mechanism is in place , You only need to adapt to the front-end and back-end views to make them easy to access , The usual way is to add a button in the button area :
<button class="oe_stat_button" name="website_publish_button"
type="object" icon="fa-globe">
<field name="website_published" widget="website_button"/>
</button>
On the front end , Some safety checks should be in place , Avoid showing it to ordinary website visitors “ edit ” Button :
<div id="website_published_button" class="float-right"
groups="base.group_website_publisher"> <!-- or any other meaningful group -->
<t t-call="website.publish_management">
<t t-set="object" t-value="blog_post"/> // The following three lines set the variable assignment in the call template
<t t-set="publish_edit" t-value="True"/>
<t t-set="action" t-value="'blog.blog_post_action'"/>
</t>
</div>
Be careful , The object must be passed to the template as a variable .
8、 ... and 、 Original website data
You can easily insert the original data into the front end
class BlogPost(models.Model):
_name = "blog.post"
_description = "Blog Post"
_inherit = ['website.seo.metadata', 'website.published.mixin']
This mixin increase 3 Fields into your model :
website_meta_title: char The type field , Add title to front page
website_meta_description: char The type field , Include a short page description ( Sometimes used for search engine results , Such as seo)
website_meta_keywords: char The type field , Contains some keywords , Help your pages to be more accurately classified by search engines ;“ upgrade ” The tool will help you easily choose keywords related to vocabulary
Front end usage examples :
Zhongyifeng digital Jiang Zhenjian
边栏推荐
猜你喜欢
随机推荐
Shell script learning record
YOLOv5使用时遇到的问题
dtcloud的消息机制(一)
内存映射原理及详解(非常实用)
Flink SQL 求上一个月 是哪个函数?
HCIP第二个实验
odoo的约束
PHP gets the names of all sub files in the directory (including cases, screenshots, and codes)
odoo owl解释
Lesson 3: stock trading III
先序和中序遍曆序列確定一顆二叉樹(還原二叉樹)
通过网上的客户经理办理炒股开户,安全吗?
Otacle table query
Hcip fourth day experiment
Famous pipeline principle and detailed explanation (very practical)
三种方法模拟实现库函数strlen,加深对strlen的理解
天田AMADA数控折弯机触摸屏维修RGM21003主机电路板维修
字符串库函数和内存操作库函数详解及模拟实现
模拟实现库函数strcpy,对strcpy的进一步理解(深刻理解重叠问题,防止内存与源重叠)
Hardware iic+dma operation sharing based on stm32f405







