本文整理汇总了Python中models.Category.select方法的典型用法代码示例。如果您正苦于以下问题:Python Category.select方法的具体用法?Python Category.select怎么用?Python Category.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.select方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_update_post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def get_update_post(id):
category = Category.select()
try:
post = Post.get(id=id)
except Post.DoesNotExist:
abort(404)
return template("admin/update.html", post=post, category=category)
示例2: __init__
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def __init__(self, table_p, parent, product=None, *args, **kwargs):
QDialog.__init__(self, parent, *args, **kwargs)
self.table_p = table_p
self.prod = product
self.parent = parent
self.filename = "Parcourire ..."
self.path_filename = None
if self.prod:
self.title = u"Modification de l'article {}".format(self.prod.name)
self.succes_msg = u"L'article <b>%s</b> a été mise à jour" % self.prod.name
try:
self.filename = self.prod.file_join.file_name
except:
pass
else:
self.succes_msg = u"L'article a été bien enregistré"
self.title = u"Ajout de nouvel article"
self.prod = Product()
self.setWindowTitle(self.title)
# self.code = LineEdit(self.prod.code)
self.name_field = LineEdit(self.prod.name)
try:
self.category_name = Category.select().where(
Category.name == self.prod.category.name).get().name
except:
self.category_name = ""
self.category_field = LineEdit(self.category_name)
self.number_parts_box_field = IntLineEdit(
str(self.prod.number_parts_box))
self.number_parts_box_field.setValidator(QIntValidator())
completion_values = [catg.name for catg in Category.all()]
completer = QCompleter(completion_values, parent=self)
completer.setCaseSensitivity(Qt.CaseInsensitive)
completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
self.category_field.setCompleter(completer)
vbox = QVBoxLayout()
formbox = QFormLayout()
formbox.addRow(FLabel(u"Nom"), self.name_field)
formbox.addRow(FLabel(u"Categorie"), self.category_field)
# formbox.addRow(
# FLabel(u"Quantité (carton)"), self.number_parts_box_field)
self.butt_parco = QPushButton(
QIcon.fromTheme('document-open', QIcon('')), self.filename)
self.butt_parco.clicked.connect(self.import_image)
butt_cancel = Warning_btt(u"Annuler")
butt_cancel.clicked.connect(self.cancel)
# formbox.addRow(FLabel(u"Image"), self.butt_parco)
butt = Button_save(u"&Enregistrer")
butt.clicked.connect(self.add_or_edit_prod)
formbox.addRow(butt_cancel, butt)
vbox.addLayout(formbox)
self.setLayout(vbox)
示例3: get
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def get(self, postid):
try:
post = Post.get(id=postid)
except Post.DoesNotExist:
raise tornado.web.HTTPError(404)
category = Category.select()
self.render('admin/post/update.html', post=post, category=category)
示例4: categories
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def categories():
"""Returns a list of tuples from the category table. Index 0 is ID & index 1 is the description.
This was implemented for WTF.SelectField in specific, but can be used if needed.
"""
category = Category.select()
category_list = []
for cat in category:
category_list.append((cat.category_id, cat.description))
return category_list
示例5: test_create_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def test_create_category(self):
"""Create a category."""
create_category(category_id="001", description="testing category")
c = Category.select().where(Category.category_id == "001")
Category.get(Category.category_id == "001").delete_instance()
self.assertEqual(
c,
"<class 'models.Category'> SELECT `t1`.`id`, "
"`t1`.`category_id`, `t1`.`description` "
"FROM `category` AS t1 WHERE (`t1`.`category_id` = %s) ['001']",
)
示例6: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def post(self):
name = self.get_argument('name', None)
slug = self.get_argument('slug', None)
q = Category.select().where(Category.name == name)
if q.count() > 0:
self.flash('cateegory exists!')
self.render('admin/category/add.html')
return
else:
Category.create(name=name, slug=slug)
self.redirect('/admin/category')
示例7: admin_index
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category 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)
示例8: index
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def index(self):
menu = Menu.select()
g_m = GeneralMeta.get_or_create(id=1)
form = MetaDataForm(obj=g_m)
categories = Category.select()
return self.render(
'admin/index.html',
categories=categories,
menu=menu,
meta_form = form
)
示例9: loadTree
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def loadTree():
# Declare empty dict of feeds (emulate sparse list)
feeds = {}
# Get categories, number of posts by category
categories = Category.select(Category, fn.Count(Post.id).alias('count')).join(Feed).join(Post).group_by(Category)
# Loop over categories
for c in categories:
# Get feeds by category
f = Feed.select().where(Feed.category == c.id).annotate(Post)
feeds[c.id] = f
return (categories, feeds)
示例10: loadJsonTree
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def loadJsonTree():
# Use collection to build nested list for tree
feeds = defaultdict(list)
# Get categories, number of posts by category
categories = Category.select(Category, fn.Count(Post.id).alias('count')).join(Feed).join(Post).group_by(Category)
# Loop over categories
all_feeds = []
for c in categories:
feeds[c.id] = {'name': c.name, 'id' : c.id, 'count': c.count, 'children' : []}
# Get feeds by category
category_feeds = Feed.select().where(Feed.category == c.id).annotate(Post)
for f in category_feeds:
feeds[c.id]['children'].append({'id': f.id, 'name': f.name, 'count' : f.count, 'url': f.url})
all_feeds.append(feeds[c.id])
return Response(json.dumps(all_feeds), mimetype='application/json')
示例11: open
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
# coding:utf-8
import csv
# 读取岗位族群分类信息
from models import Category
with open('04.csv', 'r') as csvfile:
reader = csv.DictReader(csvfile)
rows = [row for row in reader]
# 抓取数据时是深度优先
for row in rows:
if not row['parent_code']:
c = Category.create(name=row['name'], code=row['code'])
else:
parent = Category.select().where(Category.code == row['parent_code']).get()
Category.create(name=row['name'], code=row['code'], parent=parent)
示例12: get_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def get_category(self):
return Category.select()
示例13: get
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def get(self):
categories = Category.select().order_by(Category.name).iterator()
categoryList = [{'id': category.id, 'name': category.name} for category in categories]
self.write(json_encode(categoryList))
self.set_header("Content-Type", "application/json")
示例14: get_new_post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import select [as 别名]
def get_new_post():
category = Category.select()
return template("admin/newpost.html", category=category)