當前位置: 首頁>>代碼示例>>Python>>正文


Python Category.get_absolute_url方法代碼示例

本文整理匯總了Python中models.Category.get_absolute_url方法的典型用法代碼示例。如果您正苦於以下問題:Python Category.get_absolute_url方法的具體用法?Python Category.get_absolute_url怎麽用?Python Category.get_absolute_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Category的用法示例。


在下文中一共展示了Category.get_absolute_url方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_edit

# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import get_absolute_url [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

示例2: test_delete

# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import get_absolute_url [as 別名]
    def test_delete(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)

        del_url = category.get_delete_url()
        res = self.app.get(del_url)
        form = res.forms["delete_form"]
        res = form.submit().follow()
        self.assertEqual(Category.objects.all().count(), 0)
開發者ID:pokutnik,項目名稱:test_projects,代碼行數:16,代碼來源:tests.py

示例3: category_view

# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import get_absolute_url [as 別名]
def category_view(request, path="", template="catalog/product_list.html"):
    """Display the category, its child categories, and its products.

    Parameters:
     - path: url path of category
    """

    if path:
        category = get_object_or_404(Category, path=path)
        template = category.template
        products = list(category.active_products(include_children=True))
    else:
        if ENABLE_FEATURED_PRODUCTS:
            # virtual category to get a title
            category = Category(name=_("Featured products"))
            products = Product.objects.filter(active=True, featured=True)
        else:
            category = Category.objects.root_categories()[0]
            return redirect_to(request, category.get_absolute_url())

    data = {"category": category, "products": products}

    return render_to_response(template, RequestContext(request, data))
開發者ID:elprox97,項目名稱:django-simple-shop,代碼行數:25,代碼來源:views.py

示例4: test_category_list_detail

# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import get_absolute_url [as 別名]
    def test_category_list_detail(self):
        url = reverse('categories')
        res = self.c.get(url)
        self.assertContains(res, "Categories list")

        title = "Vodka based"
        self.assertNotContains(res, title)

        category = Category(title=title)
        category.save()
        res = self.c.get(url)
        self.assertContains(res, title)

        url = category.get_absolute_url()
        self.assertContains(res, url)

        res = self.c.get(url)
        self.assertContains(res, title)

        coctail_title = "Stopka"
        coctail = Coctail(title=coctail_title, category=category)
        coctail.save()
        res = self.c.get(url)
        self.assertContains(res, title)
開發者ID:pokutnik,項目名稱:test_projects,代碼行數:26,代碼來源:tests.py


注:本文中的models.Category.get_absolute_url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。