官方社群在线客服官方频道防骗查询货币工具

BBS论坛(三十一)

2025年01月15日 02:41:40
news.like.tgnews.like.tgnews.like.tgnews.like.tg

LIKE.TG | 发现全球营销软件&服务汇聚顶尖互联网营销和AI营销产品,提供一站式出海营销解决方案。唯一官网:www.like.tg

31.帖子加精和取消加精功能完成

(1)apps/models.py

代码语言:javascript
复制
class HighLight(db.Model): __tablename__='highlight_post' id = db.Column(db.Integer, primary_key=True, autoincrement=True) post_id=db.Column(db.Integer,db.ForeignKey('post.id')) create_time=db.Column(db.DateTime,default=datetime.now) post=db.relationship('PostModel',backref='highlight')

(2)cms/views.py

代码语言:javascript
复制
@bp.route('/posts/') @login_required @permission_required(CMSPermission.POSTER) def posts(): context = { 'posts': PostModel.query.all() } return render_template('cms/cms_posts.html',**context) @bp.route('/hpost/',methods=['POST']) @login_required @permission_required(CMSPermission.POSTER) def hpost(): post_id=request.form.get('post_id') if not post_id: return restful.params_error(message='请传入帖子id') post=PostModel.query.get(post_id) if not post: return restful.params_error(message='没有这篇帖子') highlight=HighLight() highlight.post=post db.session.add(highlight) db.session.commit() return restful.success() @bp.route('/uhpost/',methods=['POST']) @login_required @permission_required(CMSPermission.POSTER) def uhpost(): post_id = request.form.get('post_id') if not post_id: return restful.params_error(message='请传入帖子id') post = PostModel.query.get(post_id) if not post: return restful.params_error(message='没有这篇帖子') print(post_id) highlight=HighLight.query.filter_by(post_id=post_id).first() print(highlight) db.session.delete(highlight) db.session.commit() return restful.success()

(3)cms_posts.html

代码语言:javascript
复制
{% extends 'cms/cms_base.html' %} {% from 'common/_macros.html' import static %} {% block title %} 帖子管理 {% endblock %} {% block head %} <script src="{{ static('cms/js/posts.js') }}"></script> {% endblock %} {% block page_title %} {{ self.title() }} {% endblock %} {% block main_content %} <table class="table table-bordered"> <thead> <tr> <th>标题</th> <th>发布时间</th> <th>版块</th> <th>作者</th> <th>操作</th> </tr> </thead> <tbody> {% for post in posts %} <tr data-id={{ post.id }} data-highlight={{ 1 if post.highlight else 0 }}> <td><a target="_blank" href="{{ url_for('front.post_detail',post_id=post.id) }}">{{ post.title }}</a> </td> <td>{{ post.create_time }}</td> <td>{{ post.board.name }}</td> <td>{{ post.author.username }}</td> <td> {% if post.highlight %} <button class="btn btn-info btn-xs highlight-btn">取消加精</button> {% else %} <button class="btn btn-danger btn-xs highlight-btn">加精</button> {% endif %} &nbsp;&nbsp;&nbsp;<button class="btn btn-default btn-xs">移除</button> </td> </tr> {% endfor %} </tbody> </table> {% endblock %}

(4)cms/js/posts.js

代码语言:javascript
复制
$(function(){ $('.highlight-btn').on('click',function(){ var $this=$(this); var tr=$this.parent().parent(); var post_id=tr.attr('data-id'); var highlight=parseInt(tr.attr('data-highlight')); var url=''; if(highlight){ url='/cms/uhpost/' }else{ url='/cms/hpost/' } zlajax.post({ 'url':url, 'data':{ 'post_id':post_id }, 'success':function(data){ if(data['code']==200){ zlalert.alertSuccessToast('操作成功'); setTimeout(function(){ window.location.reload(); },500); }else{ zlalert.alertInfo(data['message']); } } }) }); });

LIKE.TG汇集全球营销软件&服务,助力出海企业营销增长。提供最新的“私域营销获客”“跨境电商”“全球客服”“金融支持”“web3”等一手资讯新闻。

点击【联系客服】 🎁 免费领 1G 住宅代理IP/proxy, 即刻体验 WhatsApp、LINE、Telegram、Twitter、ZALO、Instagram、signal等获客系统,社媒账号购买 & 粉丝引流自助服务或关注【LIKE.TG出海指南频道】【LIKE.TG生态链-全球资源互联社区】连接全球出海营销资源。

本文由LIKE.TG编辑部转载自互联网并编辑,如有侵权影响,请联系官方客服,将为您妥善处理。

This article is republished from public internet and edited by the LIKE.TG editorial department. If there is any infringement, please contact our official customer service for proper handling.


Server deployment全球论坛人工智能论坛全球峰会发展论坛战略论坛开放论坛程序员论坛互联网峰会科技峰会
加入like.tg生态圈,即可获利、结识全球供应商、拥抱全球软件生态圈加入like.tg平台,即可获利、结识全球供应商、拥抱全球营销软件生态圈加入like.tg生态资源圈,即可获利、结识全球供应商、拥抱全球软件生态圈
加入like.tg生态圈,即可获利、结识全球供应商、拥抱全球软件生态圈加入like.tg平台,即可获利、结识全球供应商、拥抱全球营销软件生态圈加入like.tg生态资源圈,即可获利、结识全球供应商、拥抱全球软件生态圈