本文整理汇总了Python中models.Category.get_all方法的典型用法代码示例。如果您正苦于以下问题:Python Category.get_all方法的具体用法?Python Category.get_all怎么用?Python Category.get_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.get_all方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_article
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
def new_article():
form = forms.EditArticleForm()
media_form = get_media_form()
form.categories.choices = [(cat.id, cat.name) for cat in Category.query.order_by('name').all()]
if form.validate_on_submit():
data = form.data
categories = [Category.query.get(i) for i in data['categories']]
article = Article(data['title'], data['pagedown'], data['description'], data['image'], categories)
db.session.add(article)
db.session.commit()
return redirect(url_for('get_article', article_id=article.id))
return render_template('edit_article.html', categories=Category.get_all(), form=form, media_form=media_form)
示例2: get_article
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
def get_article(article_id):
article = Article.query.get(article_id)
previous_article = article.get_previous()
article.body_html = Markup(markdown(article.body))
next_article = article.get_next()
link_next = {'title': None, 'url': url_for('index')} if next_article is None\
else {'title': next_article.title, 'url': next_article.get_absolute_url()}
link_previous = {'title': None, 'url': url_for('index')} if previous_article is None\
else {'title': previous_article.title, 'url': previous_article.get_absolute_url()}
comments = [comment for comment in article.comments.filter(Comment.parent_id == 0).order_by('date').all()]
form = forms.CommentRespondForm()
return render_template('article.html', categories=Category.get_all(), article=article, link_previous=link_previous,
link_next=link_next, form=form, comments=comments)
示例3: edit_article
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
def edit_article(article_id):
form = forms.EditArticleForm(request.form)
media_form = get_media_form()
#print form.data
# Populate form with all available categories
form.categories.choices = [(cat.id, cat.name) for cat in Category.query.order_by('name').all()]
if form.validate_on_submit():
data = form.data
Article.query.filter_by(id=article_id).update({"title": data['title'], "body": data['pagedown'],
"description": data['description'],
"thumbnail_id": data['image']})
Article.query.get(article_id).categories = [Category.query.get(i) for i in data['categories']]
db.session.commit()
return redirect(url_for('get_article', article_id=article_id))
else:
print form.errors
article = Article.query.get(article_id)
form.title.data = article.title
form.pagedown.data = article.body
form.description.data = article.description
form.categories.data = [cat.id for cat in article.categories]
if article.thumbnail:
form.image.set_data(article.thumbnail_id, article.thumbnail.get_url())
return render_template('edit_article.html', categories=Category.get_all(), form=form, media_form=media_form)
示例4: get_course
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
def get_course(course_id):
category = Category.query.get(course_id)
articles = category.articles
return render_template('category.html', category=category, articles=articles, categories=Category.get_all())
示例5: index
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
def index():
#recent_articles = Article.query.order_by('created_at desc').limit(3).all()
return render_template('index.html', categories=Category.get_all())
示例6:
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from lib.controller import Controller
from models import Category
import webapp2
import settings
categories = '|'.join(Category.get_all())
Controller.url_mapping = [
(r'^/([0-9]+)$', ('service', 'Article')),
(r'^/user/([0-9]+)$', ('user', 'Index')),
(r'^/user/me$', ('user', 'Index')),
]
if categories:
Controller.url_mapping.append((ur'^/(%s)$' % categories, ('service', 'Category')))
app = webapp2.WSGIApplication([('/.*', Controller)], debug=settings.DEV)