Home Announcement

 

1. Table structure

DROP TABLE IF EXISTS `notice`;

CREATE TABLE `notice` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(100) NOT NULL DEFAULT '' COMMENT '标题',
  `summary` varchar(10000) NOT NULL DEFAULT '' COMMENT '描述',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态 1:有效 0:无效',
  `view_count` int(11) NOT NULL DEFAULT '0' COMMENT '总浏览次数',
  `updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后更新时间',
  `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后插入时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='公告表';

2. Mapping

source imooc/bin/activate
cd /home/www/order/
flask-sqlacodegen 'mysql://root:[email protected]/food_db' --tables notice --outfile "common/models/member/Notice.py"  --flask

In the generated object file

order/common/models/member/Notice.py

Put

from flask_sqlalchemy import SQLAlchemy


db = SQLAlchemy()

Change to:

from application import db, app

The complete file is as follows

 

# coding: utf-8
from sqlalchemy import Column, DateTime, Integer, String
from sqlalchemy.schema import FetchedValue
from application import db, app


class Notice(db.Model):
    __tablename__ = 'notice'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue())
    summary = db.Column(db.String(10000), nullable=False, server_default=db.FetchedValue())
    status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    view_count = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
    updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
    created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())

 

 

in

order\web\templates\common\layout_main.html

Add to

                <li class="notice">
                    <a href="{
   
   { buildUrl('/notice/index') }}"><i class="fa fa-group fa-lg"></i> <span
                            class="nav-label">公告列表</span></a>
                </li>

C:\Users\huang\vincent\code\mooc\order\web\static\js\common.js

        if(  pathname.indexOf("/notice") > -1  ){
            nav_name = "notice";
        }

 

 

C:\Users\huang\vincent\code\mooc\order\www.py add

from web.controllers.member.Notice import route_notice

with

app.register_blueprint(route_notice, url_prefix="/notice")

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/huanglianggu/article/details/102297708