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


Python Tag.save方法代码示例

本文整理汇总了Python中models.Tag.save方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.save方法的具体用法?Python Tag.save怎么用?Python Tag.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Tag的用法示例。


在下文中一共展示了Tag.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_update

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
    def test_update(self):
        order = Order(name="Dummy Order")
        order.save()

        for i in range(2):
            item = Item(name="Item %i" % i, sku=str(i) * 13, price=D("9.99"), order=order, status=0)
            item.save()

        tag = Tag(name="Test", content_object=order)
        tag.save()

        res = self.client.get("/inlines/1/")

        self.assertEqual(res.status_code, 200)
        order = Order.objects.get(id=1)

        self.assertEquals(2, order.item_set.count())
        self.assertEquals("Item 0", order.item_set.all()[0].name)

        data = {
            "name": u"Dummy Order",
            "item_set-TOTAL_FORMS": u"4",
            "item_set-INITIAL_FORMS": u"2",
            "item_set-MAX_NUM_FORMS": u"",
            "item_set-0-name": "Bubble Bath",
            "item_set-0-sku": "1234567890123",
            "item_set-0-price": D("9.99"),
            "item_set-0-status": 0,
            "item_set-0-order": 1,
            "item_set-0-id": 1,
            "item_set-1-name": "Bubble Bath",
            "item_set-1-sku": "1234567890123",
            "item_set-1-price": D("9.99"),
            "item_set-1-status": 0,
            "item_set-1-order": 1,
            "item_set-1-id": 2,
            "item_set-2-name": "Bubble Bath",
            "item_set-2-sku": "1234567890123",
            "item_set-2-price": D("9.99"),
            "item_set-2-status": 0,
            "item_set-2-order": 1,
            "item_set-3-DELETE": True,
            "tests-tag-content_type-object_id-TOTAL_FORMS": 3,
            "tests-tag-content_type-object_id-INITIAL_FORMS": 1,
            "tests-tag-content_type-object_id-MAX_NUM_FORMS": u"",
            "tests-tag-content_type-object_id-0-name": u"Test",
            "tests-tag-content_type-object_id-0-id": 1,
            "tests-tag-content_type-object_id-0-DELETE": True,
            "tests-tag-content_type-object_id-1-name": u"Test 2",
            "tests-tag-content_type-object_id-2-name": u"Test 3",
        }

        res = self.client.post("/inlines/1/", data, follow=True)
        self.assertEqual(res.status_code, 200)

        order = Order.objects.get(id=1)

        self.assertEquals(3, order.item_set.count())
        self.assertEquals(2, Tag.objects.count())
        self.assertEquals("Bubble Bath", order.item_set.all()[0].name)
开发者ID:MechanisM,项目名称:django-extra-views,代码行数:62,代码来源:tests.py

示例2: post_article

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
def post_article(request,
                 success_url = "/",
                 template="articles/post.html"):
    """ Post new article """
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data['title']
            content = form.cleaned_data['content']
            tags = form.cleaned_data['tags']
            # new article
            art = Article(title=title,content=content,slug=slugify(title),author=request.user)
            art.save()
            # add tags
            for tag in tags:
                try:
                    t = Tag.objects.get(name=tag)
                except Tag.DoesNotExist:
                    t = None
                # if t doesnt exist
                if t is None:
                    t = Tag(name=tag,slug=slugify(tag))
                    t.save()
                # add the tag to the article
                art.tags.add(t)
            # set meta
            art.set_meta()
            # done here
            return HttpResponseRedirect(success_url)
    else:
        form = ArticleForm()
    
    return render_to_response(template,
                              {'form':form},
                              context_instance=RequestContext(request))
开发者ID:madrize,项目名称:dart,代码行数:37,代码来源:views.py

示例3: editarticle

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
def editarticle(request,aid):
    article=Article.objects.get(id=aid)
    maincat=MainCat.objects.all()
    nart,cart,rart,cm,tg=getthree()
    if request.method=='POST':
        title=request.POST['title']
        tags=request.POST['tag']
        cat=request.POST['cat']
        content=request.POST['content']
        tags=tags.split(',')
        tagm=[]
        
        for i in tags:
            a=Tag.objects.filter(tag=i)
            if a:
                tagm.append(a[0])
            else:
                t=Tag(tag=i)
                t.save()
                tagm.append(t)
        article.user=request.user
        article.title=title
        article.content=content
        if cat.find('mc')>0:
            maincat=MainCat.objects.get(id=cat[:cat.find('m')])
            article.maincat=maincat
        elif cat.find('-')==-1:
            dcat=DetailCat.objects.get(id=cat)
            article.maincat=dcat.maincat
            article.detailcat=dcat
        else:
            pass
        article.save()
        article.tag=tagm
        article.save()
        return redirect(getarticle,article.id)
    
    #日历
    today=today=datetime.datetime.now()
    s=calendar.HTMLCalendar(6)
    cals=list(s.itermonthdays2(today.year,today.month))
    tdarts=Article.objects.values('id','createtime').filter(createtime__year=today.year,createtime__month=today.month).order_by('createtime') #列表字典[{'createtime': datetime.datetime(2014, 4, 6, 4, 36, 32, 896000, tzinfo=<UTC>)},
    tdart=set([i['createtime'].day for i in tdarts])

    tmpq=Article.objects.exclude(createtime__year=today.year,createtime__month=today.month)
    premon=tmpq.filter(createtime__lt=today).order_by('-createtime')[:1]
    aftmon=tmpq.filter(createtime__gt=today).order_by('createtime')[:1]
    
    tt=[]
    for i in cals:
        tt.append(list(i))
    ttt=[]   
    for a in tt:
        for i in tdart:
            if a[0] == i:
                a.append(1)
        if len(a)==2:
            a.append(0)    
        ttt.append(a)
    return render_to_response('new.htm',locals(),context_instance=RequestContext(request))
开发者ID:xiaoxiao777,项目名称:django_blog,代码行数:62,代码来源:views.py

示例4: save_tag

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
def save_tag( request ) :
	user_agent = request.META['HTTP_USER_AGENT']
	tagname = request.GET['tagname']
	#will to be validate a tagname
	tag = Tag( name = tagname )
	tag.save()
	return render_to_response(u'tag_saved.html',locals())
开发者ID:romanivanov21,项目名称:web_test,代码行数:9,代码来源:views.py

示例5: addpost

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
def addpost(request):
	if request.POST:
		#files = upload_receive(request)
		form = PostForm(request.POST, request.FILES)
		if form.is_valid():
			f2 = form.save(commit=False)
			f2.pub_date = datetime.now()
			f2.save()
			tags = f2.tags
			tags = tags.split(',')
			tagobjs = Tag.objects.all()
			taglist=[]
			for i in tagobjs:					#Adding new tags
				taglist.append(i.name)
			for i in tags:
				if i not in taglist:
					obj = Tag(name=i)
					obj.save()
					print 'saved'
					print obj
					print obj.name
					taglist.append(i)
			return HttpResponseRedirect('/blog/viewposts/')
		else:
			args = {}
			args.update(csrf(request))
			args['form']=form
			args['error']='Some error in form'
			return render_to_response('addpost.html',args)
				
	else:
		args = {}
		args.update(csrf(request))
		args['form'] = PostForm()
		return render_to_response('addpost.html',args)
开发者ID:Lohit13,项目名称:PersonalBlog,代码行数:37,代码来源:views.py

示例6: ask_display

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
def ask_display(request):
        if not request.user.is_authenticated():
            raise PermissionDenied

        if request.method == 'POST':

            request_title = request.POST.get('title')
            request_text = request.POST.get('text')
            request_tags = request.POST.get('tags')
            
            if request_title == '' or request_text == '':
                return render(request, 'ask.html', {'page_title': 'New Question', 'errors': '1'})
            
            new_question = Question(title = request_title, 
                date = datetime.datetime.now(), 
                author = UserProfile.objects.get(user_account = request.user),
                text = request_text)
            
            new_question.save()
            
            for tag_str in request_tags.split(','):
                if Tag.objects.filter(name = tag_str).exists():
                    tag = Tag.objects.get(name = tag_str)
                    new_question.tags.add(tag)
                else:
                    new_tag = Tag(name = tag_str)
                    new_tag.save()
                    new_question.tags.add(new_tag)
            
            return HttpResponseRedirect('/question/{}'.format(new_question.id))
            
        return render(request, 'ask.html', {'page_title': 'New Question', 'errors': '0'})
开发者ID:TimeEscaper,项目名称:Ask_AI_TP-mail.ru,代码行数:34,代码来源:views.py

示例7: tag_helper

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
def tag_helper(data, name_field, dataset, tag):
    mps = MapPoint.objects.filter(dataset_id=dataset)
    tags = Tag.objects.filter(dataset_id=dataset).filter(tag=tag)
    if tags.count() > 1:
        appr_tags = tags.filter(approved=True)
        if appr_tags.count() > 0:
            tags = appr_tags
        tag = tags[0]
    elif tags.count() == 0:
        tag = Tag(dataset_id=dataset, tag=tag, approved=True)
        tag.save()
    else:
        tag = tags[0]

    regex = re.compile('[%s]' % re.escape(string.punctuation))
    for item in data:
        name = regex.sub(r'[\'\'\.-]*', item[name_field])
        print name
        for mp in mps.filter(name__iregex=name):
            print mp.name
            t = TagIndiv(tag=tag, mapelement=mp)
            try:
                t.save()
            except IntegrityError:
                # violate unique restraint so just don't save it
                pass
开发者ID:CSnap,项目名称:SGIS-backend,代码行数:28,代码来源:load.py

示例8: edit_photo_view

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
def edit_photo_view(request, photo_id):
    # try:
    #     photo = Photo.objects.get(pk=photo_id)
    # except Photo.DoesNotExist:
    #     raise Http404
    photo = get_object_or_404(Photo, pk=photo_id)
    if photo.owner_id == request.user.id:
        if request.method == 'POST':
            form = EditPhotoForm(request.user, data=request.POST or None, instance=photo)
            if form.is_valid():
                photo = form.save()
                if form.cleaned_data['tag']:
                    tag = Tag(name=form.cleaned_data['tag'])
                    tag.save()
                    photo.tags.add(tag)
                    photo.save()
                else:
                    form.save()
                return redirect('photorizer.views.photo_view', photo.id)
        else:
            form = EditPhotoForm(instance=photo, current_user=request.user)
            context = {'form': form, 'photo': photo}
            # return render(request, 'photorizer/edit_photo.html',
            #               {'form': form, 'photo': photo})
            return render(request, 'photorizer/edit_photo.html',
                          context)
    else:
        return render(request, 'photorizer/permission_denied.html')
开发者ID:jwhite007,项目名称:Photorize,代码行数:30,代码来源:views.py

示例9: AlbumTest

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
class AlbumTest(TestCase):
    def setUp(self):
        self.user = User(username='sholmes', email='[email protected]',
                         first_name='Sherlock', last_name="Holmes",
                         password='watson')
        self.user.full_clean()
        self.user.save()
        self.photo = Photo(owner=self.user,
                           image='images/test.png',
                           name='test',
                           caption='testing')
        self.photo.clean()
        self.photo.save()
        self.tag = Tag(name='test tag', owner=self.user)
        self.tag.clean()
        self.tag.save()
        self.photo.tags.add(self.tag)
        self.album = Album(owner=self.user,
                           name='test album')
        self.album.clean()
        self.album.save()
        self.album.photos.add(self.photo)

    def test_id_creation(self):
        self.assertIsNotNone(self.album.id)

    def test_owner_entry(self):
        self.assertEqual(self.album.name, 'test album')

    def test_name_entry(self):
        self.assertEqual(self.photo.name, 'test')

    def test_album_to_photo_association(self):
        photos = Photo.objects.filter(album=self.album.id)
        self.assertEqual(photos[0].name, 'test')
开发者ID:jwhite007,项目名称:Photorize,代码行数:37,代码来源:test_models.py

示例10: parse_page

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
    def parse_page(self, response):
        hxs = HtmlXPathSelector(response)
        title = hxs.select('//h1[@class="title"]/text()').extract()
        if title and isinstance(title, list):
            title = title[0]

        url = response.url
        tags = hxs.select('//dl[@id="viewExtCati"]/dd/a/text()').extract()
        items = hxs.select('//dd[@class="relative"]/div/a/@href').extract()
        try:
            pattern_items = [re.search(pattern, item) for item in items]
            related_items = [item.group(1) for item in pattern_items if item]
        except Exception as err:
            print(err)
            return
        try:
            num = response.request.meta['view_num']
        except Exception as err:
            print(err)
            return

        tag = Tag(name=title, url=url, num=num, tags=tags, related_items=related_items)
        try:
            print("parse title %s, view num: %s" %(title, num))
            tag.save()
        except Exception as err:
            print(err)
            return
开发者ID:chenchiyuan,项目名称:tags_spider,代码行数:30,代码来源:spider.py

示例11: upload_new_question

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
def upload_new_question(question_source, question, tags):
    new_question = Question(question = question, question_source=question_source)
    new_question.save()
    tags_final = []

    for tag in tags:
        try:
            search_tag = Tag.objects.get(tag=tag)
            tags_final.append(search_tag)
            continue
        except Tag.DoesNotExist:
            new_tag = Tag(tag=tag)
            new_tag.save()
            tags_final.append(new_tag)
            continue
        continue
    
    for tag in tags_final:
        print tag.tag

    for tag in tags_final:
        tag.questions.append(new_question)
        tag.save()
        continue

    return new_question.id
开发者ID:YNCHacks,项目名称:Qanda,代码行数:28,代码来源:views.py

示例12: test_update

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
    def test_update(self):
        order = Order(name='Dummy Order')
        order.save()

        for i in range(2):
            item = Item(name='Item %i' % i, sku=str(i) * 13, price=D('9.99'), order=order, status=0)
            item.save()

        tag = Tag(name='Test', content_object=order)
        tag.save()

        res = self.client.get('/inlines/1/')

        self.assertEqual(res.status_code, 200)
        order = Order.objects.get(id=1)

        self.assertEquals(2, order.item_set.count())
        self.assertEquals('Item 0', order.item_set.all()[0].name)

        data = {
            'name': u'Dummy Order',
            'item_set-TOTAL_FORMS': u'4',
            'item_set-INITIAL_FORMS': u'2',
            'item_set-MAX_NUM_FORMS': u'',
            'item_set-0-name': 'Bubble Bath',
            'item_set-0-sku': '1234567890123',
            'item_set-0-price': D('9.99'),
            'item_set-0-status': 0,
            'item_set-0-order': 1,
            'item_set-0-id': 1,
            'item_set-1-name': 'Bubble Bath',
            'item_set-1-sku': '1234567890123',
            'item_set-1-price': D('9.99'),
            'item_set-1-status': 0,
            'item_set-1-order': 1,
            'item_set-1-id': 2,
            'item_set-2-name': 'Bubble Bath',
            'item_set-2-sku': '1234567890123',
            'item_set-2-price': D('9.99'),
            'item_set-2-status': 0,
            'item_set-2-order': 1,
            'item_set-3-DELETE': True,
            'tests-tag-content_type-object_id-TOTAL_FORMS': 3,
            'tests-tag-content_type-object_id-INITIAL_FORMS': 1,
            'tests-tag-content_type-object_id-MAX_NUM_FORMS': u'',
            'tests-tag-content_type-object_id-0-name': u'Test',
            'tests-tag-content_type-object_id-0-id': 1,
            'tests-tag-content_type-object_id-0-DELETE': True,
            'tests-tag-content_type-object_id-1-name': u'Test 2',
            'tests-tag-content_type-object_id-2-name': u'Test 3',
        }

        res = self.client.post('/inlines/1/', data, follow=True)
        self.assertEqual(res.status_code, 200)

        order = Order.objects.get(id=1)

        self.assertEquals(3, order.item_set.count())
        self.assertEquals(2, Tag.objects.count())
        self.assertEquals('Bubble Bath', order.item_set.all()[0].name)
开发者ID:joshdrake,项目名称:django-extra-views,代码行数:62,代码来源:tests.py

示例13: test_create_tag

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
 def test_create_tag(self):
     """Create a tag and assert that its fields appear as expected."""
     tag = Tag(text='Test Tag')
     tag.full_clean()
     tag.save()
     self.assertIsInstance(tag, Tag)
     self.assertEqual(tag.text, 'Test Tag')
     self.assertIsInstance(tag.date_created, datetime)
开发者ID:geekofalltrades,项目名称:django-photo-manager,代码行数:10,代码来源:tests.py

示例14: store_tag

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
def store_tag(text, message):
  #Construct the tag.
  tag = Tag()
  tag.tag = text
  tag.message = message
  tag.save()

  return tag
开发者ID:bsmith8108,项目名称:GoBoard,代码行数:10,代码来源:models_constructors.py

示例15: TagTest

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import save [as 别名]
class TagTest(TestCase):
    def setUp(self):
        self.user1 = User.objects.create_user('tester1', 'tester1')
        self.tag = Tag(content="test", creator=self.user1)
        self.tag.save()

    def test_creator(self):
        self.assertEqual(self.tag.creator, self.user1)
        self.assertTrue(self.tag in self.user1.tags_i_created.all())
开发者ID:suzaku,项目名称:urotas,代码行数:11,代码来源:tests.py


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