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


Python Category.save方法代码示例

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


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

示例1: runTest

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
 def runTest(self):
     "Test period field options - unique types (sequenced, current and nonsequenced)"
     period = Period(lower=datetime.datetime(1996,10,1), upper=datetime.datetime(1997,1,1))
     i = Category(cat=120033, valid_time=period)
     
     # Test overlapping periods - sequenced unique.
     i.valid_time = '[1996-05-01 00:00:00.000000+0000,1996-07-01 00:00:00.000000+0000)'
     
     with _fail_atomic():
         i.save()
     
     # Test current unique.
     i.valid_time = '[1996-05-01 00:00:00.000000+0000,9999-12-30 00:00:00.000000+0000)'
     with _fail_atomic():
         i.save()
     
     # Test nonsequenced unique.
     i1 = CategoryToo(cat=120033, valid_time=period)
     i1.save()
     
     i2 = CategoryToo(cat=120033, valid_time=period)
     with _fail_atomic():
         i2.save()
     
     i2.cat = 100100
     # Saves okay.
     i2.save()
     
     i1.delete()
     i2.delete()
开发者ID:zejn,项目名称:django_temporal,代码行数:32,代码来源:tests.py

示例2: test_edit

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
    def test_edit(self):
        title = "Vodka based"
        category = Category(title=title)
        category.save()
        self.assertEqual(Category.objects.all().count(), 1)

        url = category.get_absolute_url()
        res = self.app.get(url)

        edit_url = category.get_edit_url()
        self.assert_(edit_url in res.content)

        res = self.app.get(edit_url)
        self.assert_(title in res.content)
        self.assert_("Edit" in res.content)

        form = res.form
        title += ' edited'
        form['title'] = title
        datail_res = form.submit().follow()

        self.assert_(title in datail_res.content)
        self.assert_(edit_url in datail_res.content)

        self.assertEqual(Category.objects.all().count(), 1)
开发者ID:pokutnik,项目名称:test_projects,代码行数:27,代码来源:tests.py

示例3: test_model_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
 def test_model_category(self):
     """Test category model"""
     obj = Category(name='test')
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
开发者ID:tovmeod,项目名称:anaf,代码行数:9,代码来源:tests.py

示例4: add_category_success

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
def add_category_success(request):
    if request.method == "POST":
        name = request.POST['name']
        description = request.POST['description']
        c = Category(name=name, description=description)
        c.save()
    return render_to_response('blog/add_category_success.html', context_instance=RequestContext(request))
开发者ID:lpcpp,项目名称:www,代码行数:9,代码来源:views.py

示例5: save

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
    def save(self):
        cd = self.cleaned_data
        category = Category(
            name=cd['name']
        )
        category.save()
	
开发者ID:belate,项目名称:money,代码行数:8,代码来源:forms.py

示例6: setUp

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
 def setUp(self):
     testboss = User.objects.create(username='big_boss')
     testuser = User.objects.create(username='joe__test', password='new password')
     category = Category(name="TEST")
     category.save()
     self.task = Task.objects.create(summary='Some job', content='', reported_by=testboss)
     self.task.categories.add(category)
开发者ID:davidbernick,项目名称:djangotest,代码行数:9,代码来源:tests.py

示例7: test_ensure_views_are_positive

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
    def test_ensure_views_are_positive(self):

        """
                ensure_views_are_positive should results True for categories where views are zero or positive
        """
                cat = Category(name='test',views=-1, likes=0)
                cat.save()
                self.assertEqual((cat.views >= 0), True)
开发者ID:mgzeitouni,项目名称:Django-Project,代码行数:10,代码来源:tests.py

示例8: pop_categories

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
def pop_categories():
    for n in range(10):
        category_title = "cat %s %s" % (n, datetime.datetime.now().strftime("%Y/%m/%d"))
        category_slug = category_title + ' slug'
        category_description = "Aenean erat felis, fermentum sit amet fringilla quis, porta eu dolor. Curabitur vel massa vel neque bibendum cursus non ac mi."
        new_cat = Category(title=category_title, slug=category_slug, description=category_description)
        new_cat.save()
        print('Saved %s to database.' % new_cat.title)
开发者ID:Nando-bog,项目名称:practical-django-projects-weblog,代码行数:10,代码来源:popdb.py

示例9: setUp

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
 def setUp(self):
     self.client = Client()
     p = User.objects.create_user("admin", "[email protected]", "admin")
     p.is_staff = True
     p.is_active = True
     p.is_superuser = True
     p.save()
     p = Category(name="Jobs")
     p.save()
开发者ID:scream4ik,项目名称:kavyarnya,代码行数:11,代码来源:tests.py

示例10: test_slug_line_creation

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
    def test_slug_line_creation(self):
             """
             slug_line_creation checks to make sure that when we add a category an appropriate slug line is created
             i.e. "Random Category String" -> "random-category-string"
             """

             cat = Category(name='Random Category String')
             cat.save()
             self.assertEqual(cat.slug, 'random-category-string')
开发者ID:mgzeitouni,项目名称:Django-Project,代码行数:11,代码来源:tests.py

示例11: save_categories

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
def save_categories(business_id, cat_jarray):
    for name in cat_jarray:
        category = Category()
        category.business_id = business_id
        category.category_name = name
        try:
            category.save()
        except InternalError:
            print "i dont care"
            pass
开发者ID:XiaowenLin,项目名称:cs410,代码行数:12,代码来源:json_to_mysql.py

示例12: test_ensure_first_and_last_visit

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
 def test_ensure_first_and_last_visit(self):
     cat = Category(name="test", views=1, likes=0)
     cat.save()
     p = Page(title="xixi", category=cat)
     p.save()
     # response = self.client.get(reverse('add_page',kwargs={'catgory_slug_name':cat.slug}))
     response = self.client.get(reverse("goto"))
     first_visit = p.first_visit
     last_visit = p.last_visit
     self.assertEqual((first_visit < last_visit), True)
开发者ID:wanzifa,项目名称:django-exercise,代码行数:12,代码来源:tests.py

示例13: admin_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
def admin_category():

    form = CategoryForm()
    if request.method == 'POST' and form.validate_on_submit():
        cat_name = form.cat_name.data.strip()
        cat_description = form.cat_description.data.strip()
        Category.save(cat_name, cat_description)
        categories = Category.query.all()
        return render_template('admin_categories.html', title='Admin', user=current_user, categories=categories)

    return render_template('admin_new_category.html', title='Admin', form=form, user=current_user)
开发者ID:FengNongtheWindCoder,项目名称:flaskblog,代码行数:13,代码来源:views.py

示例14: get_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
 def get_category(self, category_name):
     category = None
     if category_name != None:
         try:
             category = Category.objects.get(name=category_name)
         except Category.DoesNotExist:
                 category = Category()
                 category.name = category_name
                 category.save()
          
     return category
开发者ID:samantafernandez,项目名称:bikeshop,代码行数:13,代码来源:importer.py

示例15: fetch__update_database

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import save [as 别名]
def fetch__update_database():
    """
    Fetch & Update the database.
    Return : tuple (categoriesUpdated, categoriesInserted, eventsUpdated, eventsInserted)
    """
    categories_updated = list()
    categories_inserted = list()
    events_updated = list()
    events_inserted = list()

    for u in create_urls(1, json.load(urllib2.urlopen(create_urls(1, 1)[0]))['totalPages']):
        for e in json.load(urllib2.urlopen(u))['events']:
            cat = None
            try:
                cat = Category.objects.get(external_id=e['category']['objectId'])

                if cat.name != e['category']['name']:
                    cat.name = e['category']['name']
                    categories_updated.append(cat.name)
            except ObjectDoesNotExist:
                cat = Category(external_id=e['category']['objectId'], name=e['category']['name'])
                categories_inserted.append(cat.name)
            cat.save()  # NOT THREAD-SAFE !

            event = None
            description = re.sub('\\n', ' ', e['description'])
            try:
                event = Event.objects.get(external_id=e['objectId'])
                if unicode(event.category.external_id) != e['category']['objectId'] \
                    or unicode(event.external_id) != e['objectId'] \
                    or unicode(event.name) != e['name'] \
                    or unicode(event.website) != e['website'] \
                    or unicode(event.description) != description:

                    event.category = cat
                    event.external_id = e['objectId']
                    event.name = e['name']
                    event.website = e['website']
                    event.description = description
                    events_updated.append(event.name)

            except ObjectDoesNotExist:
                event = Event(category=cat,
                              external_id=e['objectId'],
                              name=e['name'],
                              website=e['website'],
                              description=description)

                events_inserted.append(event.name)

            event.save()  # NOT THREAD-SAFE !

    update_weight_database()
    return categories_updated, categories_inserted, events_updated, events_inserted
开发者ID:Diego999,项目名称:Social-Recommendation-System,代码行数:56,代码来源:functions.py


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