本文整理匯總了Python中tags.models.Tag.region方法的典型用法代碼示例。如果您正苦於以下問題:Python Tag.region方法的具體用法?Python Tag.region怎麽用?Python Tag.region使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tags.models.Tag
的用法示例。
在下文中一共展示了Tag.region方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_fix_tags
# 需要導入模塊: from tags.models import Tag [as 別名]
# 或者: from tags.models.Tag import region [as 別名]
def test_fix_tags(self):
"""
Test the `fix_tags` utility function.
"""
from pages.models import Page
from tags.tag_utils import fix_tags
#########################
# Create some test regions
#########################
sf = Region(full_name="San Francisco Test", slug='sftest')
sf.save()
mission = Region(full_name="Mission", slug="mission")
mission.save()
#########################
# Create some test tags
#########################
park = Tag(name='park', region=sf)
park.save()
fun = Tag(name='fun', region=sf)
fun.save()
#########################
# Add the tags to a test page
#########################
page = Page(name="Duboce Park", content="<p>Park.</p>", region=sf)
page.save()
pts = PageTagSet(
page=page,
region=sf
)
pts.save()
pts.tags.add(park)
pts.tags.add(fun)
pts.save()
# Now do something odd and make one of the referenced `Tag`s point
# to a different region than the PageTagSet.
fun.region = mission
fun.save()
self.assertTrue(pts.tags.filter(region=mission).exists())
# Then attempt a fix:
fix_tags(sf, PageTagSet.objects.filter(id=pts.id))
pts = PageTagSet.objects.get(page=page, region=sf)
self.assertFalse(pts.tags.filter(region=mission).exists())
# Check that this is fixed in historical versions as well
for pts_h in pts.versions.all():
self.assertFalse(pts_h.tags.filter(region=mission).exists())