当前位置: 首页>>代码示例>>Python>>正文


Python Category.save方法代码示例

本文整理汇总了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)
开发者ID:guillermocandia,项目名称:tienda,代码行数:30,代码来源:cargar_categorias.py

示例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)
开发者ID:mykytamorachov,项目名称:SaveYourPage,代码行数:11,代码来源:views.py

示例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')
开发者ID:chiranjeevjain,项目名称:bookmark-manager,代码行数:15,代码来源:bulk_adders.py

示例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)
开发者ID:xueyue123,项目名称:zhBlog,代码行数:19,代码来源:back_manage.py

示例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/')
开发者ID:chiranjeevjain,项目名称:bookmark-manager,代码行数:22,代码来源:bulk_adders.py

示例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
开发者ID:xueyue123,项目名称:zhBlog,代码行数:6,代码来源:blog.py

示例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"""
帮助
===================================
#.........这里部分代码省略.........
开发者ID:yxm0513,项目名称:7topdig,代码行数:103,代码来源:data.py


注:本文中的app.models.Category.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。