from sqlalchemy import Table, func
from model.tt_user import User
from common.create_connect import extendsModel
FactorySession,FactoryModel,md=extendsModel()
class Article(FactoryModel):
__table__=Table('tt_article',md,autoload=True)
# 定义操作
#指定分页limit限制和最新显示offset select * from user limit param1 offset param2 ; 从(param2+1)条数据开始,取 param1条数据
def find_with_nickname(self,start,count):
result=FactorySession.query(Article,User.nickname).join(User,User.userid==Article.userid)\
.filter(Article.hidden==0,Article.drafted==1,Article.checked==1)\
.order_by(Article.articleid.asc()).limit(count).offset(start).all()
return result #将数据库表映射到对象
#获取文章数量
def find_view_artilce_count(self):
count=FactorySession.query(Article).filter(Article.hidden==0,Article.drafted==1,Article.checked==1).count()
return count
#根据文章类型获取文章
def find_article_by_type(self,type,start,count):
result=FactorySession.query(Article,User.nickname).filter(Article.hidden==0,Article.drafted==1,Article.checked==1,Article.type==type)\
.order_by(Article.articleid.asc()).limit(count).offset(start).all() #按文章类型将所有文章查出来
return result
#根据文章类型获取不同文章类型的数量
def get_diffrent_articelcount_by_type(self,type):
articel_count = FactorySession.query(Article).filter(Article.hidden == 0, Article.drafted == 1,
Article.checked == 1,Article.type==type).count()
return articel_count
#根据文章标题搜索
def serach_by_headline(self,headline,start,count):
result = FactorySession.query(Article, User.nickname).filter(Article.hidden == 0, Article.drafted == 1,
Article.checked == 1, Article.headline.like('%'+headline+'%') ) \
.order_by(Article.articleid.asc()).limit(count).offset(start).all() # 按文章类型将所有文章查出来
return result
#统计搜索标题的总数量
def getcount_by_headline(self,headline):
articel_count = FactorySession.query(Article).filter(Article.hidden == 0, Article.drafted == 1,
Article.checked == 1, Article.headline.like('%'+headline+'%')).count()
return articel_count
#最新文章推荐
def get_new_article(self): #倒叙输出文章
result=FactorySession.query(Article.articleid,Article.headline)\
.filter(Article.hidden==0,Article.drafted==1,Article.checked==1,Article.recommended==1)\
.order_by(Article.articleid.desc()).limit(9).all()
return result
#最多阅读文章
def get_max_readed_articel(self):
result = FactorySession.query(Article.articleid, Article.headline) \
.filter(Article.hidden == 0, Article.drafted == 1, Article.checked == 1, Article.recommended == 1) \
.order_by(Article.readcount.desc()).limit(9).all() # 倒叙输出文章
return result
#特别推荐从推荐随机生成文章
def get_random_article(self):
result = FactorySession.query(Article.articleid, Article.headline) \
.filter(Article.hidden == 0, Article.drafted == 1, Article.checked == 1, Article.recommended == 1) \
.order_by(func.rand()).limit(9).all() # 倒叙输出文章
return result
#将上述三个结果一次返回
def get_three_result(self):
new= self.get_new_article()
max=self.get_max_readed_articel()
random=self.get_random_article()
return new,max,random
#根据文章id搜索文章
def get_article_by_id(self,id):
result = FactorySession.query(Article).filter(Article.hidden == 0, Article.drafted == 1,
Article.checked == 1, Article.articleid == id).all()
return result
#每阅读一次文章阅读量加一
def update_read_count(self,articleid):
result = FactorySession.query(Article).filter(Article.articleid==articleid).first()
result.readcount += 1
FactorySession.commit()
'''
def test_function(self):
result = FactorySession.query(Article.headline).filter(Article.userid == 3).first()
return result
'''
"""测试函数
if __name__=='__main__':
article = Article()
#result1 = article.get_diffrent_articelcount_by_type(4)
#result1=article.test_function()
#result1=article.get_article_by_id(50)
#result1=article.get_new_article()
#print(result1)
#result=article.update_read_count(1)
print(article.get_random_article()[0])
"""
没有合适的资源?快使用搜索试试~ 我知道了~
flask搭建个人博客
共361个文件
png:95个
js:82个
gif:45个
需积分: 0 25 下载量 104 浏览量
2023-03-26
21:02:37
上传
评论 2
收藏 11.13MB ZIP 举报
温馨提示
flask搭建个人博客的源码和数据库数据
资源推荐
资源详情
资源评论
收起资源包目录
flask搭建个人博客 (361个子文件)
bootstrap.css 143KB
bootstrap.min.css 119KB
ueditor.css 44KB
ueditor.min.css 34KB
bootstrap-theme.css 25KB
bootstrap-theme.min.css 23KB
video-js.css 21KB
image.css 19KB
video.css 15KB
attachment.css 15KB
video-js.min.css 11KB
shCoreDefault.css 7KB
scrawl.css 4KB
codemirror.css 3KB
charts.css 3KB
background.css 2KB
emotion.css 2KB
dialogbase.css 2KB
music.css 2KB
index2.css 2KB
edittable.css 1KB
template.css 1KB
webuploader.css 515B
help.css 395B
iframe.css 42B
vjs.eot 3KB
UEditorSnapscreen.exe 508KB
wface.gif 49KB
jxface2.gif 40KB
yface.gif 28KB
bface.gif 27KB
icons.gif 20KB
file-icons.gif 20KB
file-icons.gif 20KB
tface.gif 19KB
fface.gif 18KB
cface.gif 8KB
icons-all.gif 4KB
videologo.gif 2KB
cancelbutton.gif 1KB
button-bg.gif 1KB
lock.gif 1KB
alignicon.gif 1KB
word.gif 1019B
icon_doc.gif 1012B
icon_psd.gif 1009B
icon_rar.gif 1007B
icon_xls.gif 1005B
icon_ppt.gif 1001B
icon_mv.gif 1001B
icon_pdf.gif 996B
icon_mp3.gif 986B
icon_txt.gif 970B
icon_jpg.gif 950B
icon_exe.gif 949B
icon_chm.gif 923B
loading.gif 734B
icons.gif 453B
icons.gif 453B
icons.gif 453B
success.gif 445B
success.gif 445B
success.gif 445B
cursor_v.gif 370B
cursor_h.gif 253B
anchor.gif 184B
highlighted.gif 111B
unhighlighted.gif 111B
bg.gif 84B
pagebreak.gif 54B
spacer.gif 43B
0.gif 43B
.gitignore 184B
index1.html 28KB
searchtest.html 27KB
articletype.html 26KB
index3.html 21KB
index4.html 19KB
index2.html 18KB
read.html 14KB
base.html 12KB
log.html 8KB
search.html 8KB
display.html 8KB
article.html 8KB
index.html 7KB
wordimage.html 6KB
map.html 6KB
emotion.html 6KB
image.html 6KB
show.html 5KB
charts.html 5KB
link.html 5KB
write.html 4KB
insertframe.html 4KB
searchreplace.html 4KB
video.html 4KB
gmap.html 4KB
scrawl.html 4KB
side.html 4KB
共 361 条
- 1
- 2
- 3
- 4
资源评论
xvwen
- 粉丝: 2w+
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功