本文整理汇总了Python中models.Image.is_primary方法的典型用法代码示例。如果您正苦于以下问题:Python Image.is_primary方法的具体用法?Python Image.is_primary怎么用?Python Image.is_primary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Image
的用法示例。
在下文中一共展示了Image.is_primary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_uploading
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import is_primary [as 别名]
def test_uploading(self):
"""
Test that uploading an image works
"""
test_site = Site.objects.all()[0]
test_site_ct = ContentType.objects.get_for_model(test_site)
test_site_id = test_site.id
# check that there are no images
self.assertEqual( Image.objects.all().count(), 0 )
# create an image
first = Image(
content_type = test_site_ct,
object_id = test_site_id,
source = 'test directory',
)
first.image.save(
name = 'foo.png',
content = self.get_test_file_content('foo.png'),
)
# check that the is_primary is true
self.assertTrue( first.is_primary )
# create another image
second = Image(
content_type = test_site_ct,
object_id = test_site_id,
source = 'test directory',
)
second.image.save(
name = 'bar.png',
content = self.get_test_file_content('bar.png'),
)
# check that is_primary is false
self.assertTrue( self.reload_image(first).is_primary )
self.assertFalse( self.reload_image(second).is_primary )
# change is_primary on second image
second.is_primary = True
second.save()
# check that it changed on first too
self.assertFalse( self.reload_image(first).is_primary )
self.assertTrue( self.reload_image(second).is_primary )
# create a third image with is_primary true at the start
third = Image(
content_type = test_site_ct,
object_id = test_site_id,
source = 'test directory',
is_primary = True,
)
third.image.save(
name = 'baz.png',
content = self.get_test_file_content('baz.png'),
)
# check that is_primary is updated for all
self.assertFalse( self.reload_image(first).is_primary )
self.assertFalse( self.reload_image(second).is_primary )
self.assertTrue( self.reload_image(third).is_primary )
# Now try to create an thumbnail with sorl. If this fails
# with "IOError: decoder zip not available", then probably
# this is a problem with an old version of PIL, or one that
# wasn't installed when the right build dependencies were
# present. The simplest solution in most solutions is:
# pip uninstall PIL
# pip install pillow
im = get_thumbnail(third.image, '100x100', crop='center', quality=99)
示例2: test_uploading
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import is_primary [as 别名]
def test_uploading(self):
"""
Test that uploading an image works
"""
test_site = Site.objects.all()[0]
test_site_ct = ContentType.objects.get_for_model(test_site)
test_site_id = test_site.id
# check that there are no images
self.assertEqual( Image.objects.all().count(), 0 )
# create an image
first = Image(
content_type = test_site_ct,
object_id = test_site_id,
source = 'test directory',
)
first.image.save(
name = 'foo.png',
content = self.get_test_file_content('foo.png'),
)
# check that the is_primary is true
self.assertTrue( first.is_primary )
# create another image
second = Image(
content_type = test_site_ct,
object_id = test_site_id,
source = 'test directory',
)
second.image.save(
name = 'bar.png',
content = self.get_test_file_content('bar.png'),
)
# check that is_primary is false
self.assertTrue( self.reload_image(first).is_primary )
self.assertFalse( self.reload_image(second).is_primary )
# change is_primary on second image
second.is_primary = True
second.save()
# check that it changed on first too
self.assertFalse( self.reload_image(first).is_primary )
self.assertTrue( self.reload_image(second).is_primary )
# create a third image with is_primary true at the start
third = Image(
content_type = test_site_ct,
object_id = test_site_id,
source = 'test directory',
is_primary = True,
)
third.image.save(
name = 'baz.png',
content = self.get_test_file_content('baz.png'),
)
# check that is_primary is updated for all
self.assertFalse( self.reload_image(first).is_primary )
self.assertFalse( self.reload_image(second).is_primary )
self.assertTrue( self.reload_image(third).is_primary )