本文整理汇总了Python中models.Post.select方法的典型用法代码示例。如果您正苦于以下问题:Python Post.select方法的具体用法?Python Post.select怎么用?Python Post.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: admin_index
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def admin_index():
post_count = Post.select().count()
comm_count = Comment.select().count()
tag_count = Tag.select().count()
cate_count = Category.select().count()
author = Author.get(id=1)
posts = Post.select().paginate(1, 5)
comments = Comment.select().order_by(('published', 'desc')).paginate(1, 5)
return template('admin/index.html', posts=posts, comments=comments,
post_count=post_count, comm_count=comm_count,
tag_count=tag_count, cate_count=cate_count, author=author)
示例2: test_subquery
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def test_subquery(self):
self.create_data(10)
query = User.where(User.id._in(Post.select(Post.user_id))).select()
result = query.execute()
assert result.count == 10
query = User.where(id=(Post.select(fn.max(Post.user_id)))).select()
result = query.execute()
assert result.count == 1
assert result.one().id == 10
query = User.where(
User.id < Post.select(fn.min(Post.user_id))).select()
result = query.execute()
assert result.count == 0
示例3: feed
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def feed(id=None):
# Get feed number <id>
try:
feed = Feed.get(Feed.id == id)
except Feed.DoesNotExist:
return jsonify(**FEED_NOT_FOUND)
# populate Category tree
(categories, feeds) = loadTree()
# Get posts in decreasing date order
posts = Post.select().join(Feed).where(Feed.id == id).order_by(Post.published.desc()).paginate(1, 50)
# Create human-readable datestamps for posts
datestamps = loadDates(posts)
# Select return format on requested content-type?
if request.json is None:
# Render feed page template
return render_template("feed.html",
categories=categories,
feeds=feeds,
feed=feed,
posts=posts,
datestamps=datestamps)
else:
# Return JSON here for client-side formatting?
return jsonify(response=[dict(feed=feed, posts=posts)])
示例4: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def get(self, tagname, page=1):
tags = Tag.select().where(Tag.name == tagname)
postids = [tag.post for tag in tags]
pagination = Pagination(Post.select().where(
Post.id << postids), int(page), per_page=8)
self.render('archive.html', pagination=pagination,
name=tagname, obj_url='/tag/%s' % (tagname), flag='tag')
示例5: page_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def page_post(num):
if num < 1:
abort(404)
posts = Post.select().paginate(num, 5)
post_count = posts.count()
pages = (post_count - 1) / 5 + 1
return template('index.html', posts=posts, page=num, pages=pages)
示例6: test_not_in_select
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def test_not_in_select(self):
self.create_data(4)
query = User.where(
User.id.not_in(Post.select(Post.user_id))
).select()
results = query.execute()
assert results.count == 0
示例7: admin
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def admin():
username = request.get_cookie('admin', secret='some-secret-key')
if username:
posts = Post.select().limit(paginate_by)
return template('templates/admin.tpl', posts=posts, sp=numer_page())
else:
return template('templates/index.tpl')
示例8: category
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def category(id=None):
# Get category #id
try:
category = Category.get(Category.id == id)
except Category.DoesNotExist:
return jsonify(**CATEGORY_NOT_FOUND)
# Populate Category tree
(categories, feeds) = loadTree()
# Get posts in category in decreasing date order
posts = Post.select().join(Feed).join(Category).where(Category.id == id).order_by(Post.published.desc()).paginate(1, 50)
# Create human-readable datestamps for posts
datestamps = loadDates(posts)
# Return mode dependent on Content-Type?
if request.json is None:
# Render category page template
return render_template("category.html",
category=category,
categories=categories,
feeds=feeds,
posts=posts,
datestamps=datestamps)
else:
# Return JSON data structure
return jsonify(response=[dict(categories=categories, feeds=feeds, posts=posts)])
示例9: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def get(self,slug):
query = Post.select()
post = get_object_or_404(query,Post.slug==slug)
for comment in post.comments:
comment.delete_instance()
PostIndex.delete().where(PostIndex.post_id ==post.id).execute()
post.delete_instance()
return redirect('/admin/')
示例10: specific_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def specific_post(year, month, slug):
try:
last_post = Post.select().where(Post.published==True).where(Post.slug==slug).where(Post.date.year==year).where(Post.date.month==month).get()
page_title = last_post.title
except Post.DoesNotExist:
abort(404, "POST not found.")
return {'post': last_post, 'page_title': page_title}
示例11: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def get(self,year,month,page=1):
format = '%%%s-%s%%'%(year,month)
posts = Post.select().where(Post.created ** format)
pagination = Pagination(posts,int(page),per_page=8)
self.render('archive.html',
year=year,month=month,
pagination=pagination,flag='archives',
obj_url='/archives/%s/%s'%(year,month))
示例12: get_categories
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def get_categories():
categories = []
category = Post.select()
for cat in category:
if cat.category not in categories:
categories.append(cat.category)
return categories
示例13: archives
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def archives():
months = [x.date for x in Post.select()]
unique_months = list(set(months))
return render_template('archives.html', posts=get_posts(),
recent_posts=get_posts(),
categories=get_categories(),
months=unique_months,
archives=get_archive())
示例14: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def get(self, page=1):
search_query = request.args.get('q')
if search_query:
posts = Post.search_all(search_query)
max_page = PostIndex.max_post_page_all(search_query)
else:
max_page = Post.max_post_page_all()
posts = Post.select().order_by(Post.timestamp.desc()).paginate(page, POST_PER_PAGE)
return render_template('posts/list.html', posts=posts, page=page, max_page = max_page)
示例15: index
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import select [as 别名]
def index():
try:
last_post = Post.select().where(Post.published==True).order_by(Post.date).limit(1).get()
page_title = last_post.title
except Post.DoesNotExist:
last_post = None
page_title = 'Nothing posted yet.'
return {'post': last_post, 'page_title': page_title}