本文整理汇总了Python中app.models.Category.save方法的典型用法代码示例。如果您正苦于以下问题:Python Category.save方法的具体用法?Python Category.save怎么用?Python Category.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Category
的用法示例。
在下文中一共展示了Category.save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import save [as 别名]
def handle(self, *args, **options):
archivo = args[0]
f = open(archivo, 'r')
l = f.readlines()
count = 0
for c in l:
c = c[1:]
c = c[:-2]
slug = c.replace(' ', '-')
slug = slug.replace(',', '')
slug = slug.decode('latin-1')
slug = unicodedata.normalize('NFKD', slug).encode('ASCII', 'ignore')
slug = slug.lower()
category = Category()
category.name = c
category.slug = slug
category.order = 0
category.active = True
try:
category.save()
count += 1
self.stdout.write('Categoria %s almacenada' % c)
except Exception:
self.stdout.write('Categoria %s NO almacenada' % c)
self.stdout.write('Se almacenaron %d categorias' % count)
示例2: addCategory
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import save [as 别名]
def addCategory(request):
if request.method == 'GET':
category_name = request.GET.get('name')
user = User.objects.get(pk=request.user.id)
category = Category(name=category_name, user=user)
category.save()
return redirect('home')
else:
return Response(status=403)
示例3: add_five_random_categories
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import save [as 别名]
def add_five_random_categories(request):
categories = Category.objects.filter(user=request.user)
for idx in range(5):
raw_name = list(string.ascii_lowercase)
random.shuffle(raw_name)
name = ''.join(raw_name[:6])
column_number = random.randrange(0, 6)
row_number = get_max_row_number(categories.filter(column_number=column_number)) + 1
progress_bar_color = get_random_color()
category = Category(user=request.user, name=name, column_number=column_number,
row_number=row_number, progress_bar_color=progress_bar_color)
category.save()
return HttpResponseRedirect('/b/edit')
示例4: add_category
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import save [as 别名]
def add_category(request):
if request.method == "POST" and request.is_ajax():
category_name = request.POST.get("name")
if category_name == "":
return HttpResponse("分类名称不能为空")
# print category_name #打印分类名称
user = User.objects.get(username=request.user.username)
# print user.username #打印当前用户名
category = Category(name=category_name, user=user)
category.save()
return HttpResponse("添加成功") # ajax post要返回一个值,否则报500错误
else:
# print 'get请求, 返回管理界面!'
category_list = Category.objects.filter(user=request.user)
# category_list = Category.objects.all()
content_dict = {"categories": category_list}
return render(request, "admin/category_manage.htm", content_dict)
示例5: add_starter_bookmarks
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import save [as 别名]
def add_starter_bookmarks(request):
old_categories = Category.objects.filter(user=request.user)
for category in old_categories:
category.delete()
# Delete or not?
for (name, column_number, row_number, progress_bar_color) in predefined_category_details:
category = Category(user=request.user, name=name, column_number=column_number,
row_number=row_number, progress_bar_color=progress_bar_color)
category.save()
categories = Category.objects.filter(user=request.user)
for category_name in predefined_category_names:
category = categories.filter(name=category_name)[0]
for (name, link, row_number, glyphicon) in predefined_bookmarks[category_name]:
bookmark = Bookmark(category=category, name=name, link=link, row_number=row_number, glyphicon=glyphicon)
bookmark.save()
return HttpResponseRedirect('/b/')
示例6: add_category
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import save [as 别名]
def add_category(user, name):
cat = Category(user=user, name=name)
cat.save()
return cat
示例7: initdb
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import save [as 别名]
def initdb():
# fix for CASCADE not work issue
db.session.execute('PRAGMA foreign_keys=ON;')
try:
db.create_all()
except:
db.drop_all()
# add some records
try:
# add some users
admin = createUser(u'admin', u'111111', u'[email protected]', 300)
simon = createUser(u'simon', u'111111', u'[email protected]', 300)
ray = createUser(u'ray', u'111111', u'[email protected]')
yxm0513 = createUser(u'yxm0513', u'111111', u'[email protected]', 200)
gonglidi = createUser(u'gonglidi', u'111111', u'[email protected]')
infoprint(u"create users table successfully.", 'successfully')
# add some tags
# search function
search_url = 'http://api.douban.com/book/subjects?tag=python&max-results=200'
books = parse(search_url)
link = ''
ID = []
for e in books['entries']:
if hasattr(e, 'link'):
link = e.link
p = re.compile(r'(?P<id>\d+)')
r = p.search(link)
id = r.group("id")
ID.append(id)
# add some book info from douban
#ID = range(11505944, 11505960)
for id in ID:
book = parse(setting.DOUBAN_API_PATH + '/' + str(id))
title = u''
summary = u''
tags = u''
for e in book['entries']:
if hasattr(e, 'title'):
title = e.title
if hasattr(e, 'summary'):
summary = e.summary
if hasattr(e, 'db_tag'):
if 'python' in e.db_tag.get('name').lower():
tags = e.db_tag.get('name')
else:
tags = e.db_tag.get('name') + ',python'
post = createPost(simon, title, summary, tags=tags)
infoprint(u"create posts table successfully.", 'successfully')
# add some page info
rules_source = u"""
免责条款
=================================
:作者: simon.yang.sh <at> gamil <dot> com
:版本: 0.1 of 2012/07
关于提交内容
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 如果你觉得有什么破坏条款的请 联系我们
* 如果你愿意监督我们的内容,联系我们吧。
"""
rules = Page(u"免责条款", rules_source)
rules.save()
about_source = u"""
===================================
关于我们
===================================
我们想做的是什么呢,简单的说就是
*用 digg的方式给用户提供一个读书的榜单.*
缘由:
通常我们会在很多论坛看见很多新手问类似于,“我想学python,各位大侠有没有好的书推荐”, 我们为什么不用digg的方式来给我们构建这么的榜单呢,让大家的投票说话。
我们有什么不一样:
* 我们只做过滤工作,给用户需要的信息 -- 做信息的减法
* 豆瓣也有书,但不是一个榜单。
* 我们很社会化,可构建圈子,评论也需要言简意赅,字数被限制在140个字符
* 未来期望构建知识的架构图,树形的展示知识的架构,给学习者直观的知道,学习者可以由浅入深的研究自己希望的课题。
"""
about = Page(u"关于我们", about_source)
about.save()
api_source = u"""
API
===================================
* Coming Soon!!!
"""
api = Page(u"API", api_source)
api.save()
help_source = u"""
帮助
===================================
#.........这里部分代码省略.........