本文整理汇总了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)
示例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)
示例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))
示例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)