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


Python models.ImageField方法代码示例

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


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

示例1: handle

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import ImageField [as 别名]
def handle(self, *args, **options):
        storage = DefaultStorage()

        for model in _get_models(['shapes', 'photos', 'shapes']):
            has_images = False

            # transfer image fields
            for f in model._meta.fields:
                if isinstance(f, models.ImageField):
                    has_images = True
                    if hasattr(storage, 'transfer'):
                        filenames = model.objects.all() \
                            .values_list(f.name, flat=True)
                        print '%s: %s' % (model, f)
                        for filename in progress.bar(filenames):
                            if filename and storage.local.exists(filename):
                                storage.transfer(filename)

            # transfer thumbs
            if has_images:
                print '%s: thumbnails' % model
                ids = model.objects.all().values_list('id', flat=True)
                ct_id = ContentType.objects.get_for_model(model).id
                for id in progress.bar(ids):
                    ensure_thumbs_exist_task.delay(ct_id, id) 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:27,代码来源:transfer_all_images.py

示例2: to_json

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import ImageField [as 别名]
def to_json(self):
        """
        序列模型实例,让具体的模型实例可以 json 化

        属性说明:
        a = RecodeImage.objects.get(recode_number="5+8")
        a._meta --> (<django.db.models.fields.AutoField: id>,
                    <django.db.models.fields.CharField: recode_number>,
                    <django.db.models.fields.files.ImageField: recode_image_path>,
                    <django.db.models.fields.DateTimeField: add_time>)
                    这是一个可迭代的对象,通过遍历,取得每个字段的名字(field.name)
        getattr(self, attr) -->  获取模型实例的字段值
        ImageField 字段使用 str() 字符串化
        """

        fields = []
        for field in self._meta.fields:
            fields.append(field.name)

        d = {}
        for attr in fields:
            d[attr] = str(getattr(self, attr))

        return json.dumps(d) 
开发者ID:fandiandian,项目名称:fansfood,代码行数:26,代码来源:models.py

示例3: test_pillow_installed

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import ImageField [as 别名]
def test_pillow_installed(self):
        try:
            from PIL import Image  # NOQA
        except ImportError:
            pillow_installed = False
        else:
            pillow_installed = True

        class Model(models.Model):
            field = models.ImageField(upload_to='somewhere')

        field = Model._meta.get_field('field')
        errors = field.check()
        expected = [] if pillow_installed else [
            Error(
                'Cannot use ImageField because Pillow is not installed.',
                hint=('Get Pillow at https://pypi.org/project/Pillow/ '
                      'or run command "pip install Pillow".'),
                obj=field,
                id='fields.E210',
            ),
        ]
        self.assertEqual(errors, expected) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:test_ordinary_fields.py

示例4: get_field_attrs

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import ImageField [as 别名]
def get_field_attrs(self, attrs, db_field, **kwargs):
        if isinstance(db_field, models.ImageField):
            attrs['widget'] = AdminImageWidget
            attrs['form_class'] = AdminImageField
            self.include_image = True
        return attrs 
开发者ID:stormsha,项目名称:StormOnline,代码行数:8,代码来源:images.py

示例5: get_field_result

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import ImageField [as 别名]
def get_field_result(self, result, field_name):
        if isinstance(result.field, models.ImageField):
            if result.value:
                img = getattr(result.obj, field_name)
                result.text = mark_safe('<a href="%s" target="_blank" title="%s" data-gallery="gallery"><img src="%s" class="field_img"/></a>' % (img.url, result.label, img.url))
                self.include_image = True
        return result

    # Media 
开发者ID:stormsha,项目名称:StormOnline,代码行数:11,代码来源:images.py

示例6: test_create_translation_field_has_correct_descriptor

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import ImageField [as 别名]
def test_create_translation_field_has_correct_descriptor(self):
        field = create_translation_field(models.fields.CharField(), "en")
        assert field.descriptor_class == TranslationDescriptor

        field = create_translation_field(models.FileField(), "en")
        assert field.descriptor_class == files.FileTranslationDescriptor

        field = create_translation_field(models.ImageField(), "en")
        assert field.descriptor_class == files.FileTranslationDescriptor

        field = create_translation_field(models.fields.TextField(), "en")
        assert field.descriptor_class == TranslationDescriptor 
开发者ID:ulule,项目名称:django-linguist,代码行数:14,代码来源:test_metaclass.py

示例7: formfield

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import ImageField [as 别名]
def formfield(self, **kwargs):
        defaults = {'form_class': forms.ImageField}
        defaults.update(kwargs)
        return super().formfield(**defaults) 
开发者ID:liqd,项目名称:adhocracy4,代码行数:6,代码来源:fields.py

示例8: test_should_image_convert_string

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import ImageField [as 别名]
def test_should_image_convert_string():
    assert_conversion(models.ImageField, graphene.String) 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:4,代码来源:test_converter.py

示例9: render

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import ImageField [as 别名]
def render(self, obj):
        src = helper.call_or_get(obj, self.attr)

        if isinstance(src, ModelImageField):
            src = settings.MEDIA_URL + src

        p_params = {}
        for key in self.params.keys():
            p_params[key] = helper.call_or_get(obj, self.params[key])

        p_params['src'] = src

        return '<img%s/>' % (
            flatatt(p_params)
        ) 
开发者ID:ebertti,项目名称:django-admin-easy,代码行数:17,代码来源:field.py

示例10: test_image_field

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import ImageField [as 别名]
def test_image_field(self):
        field = models.ImageField(upload_to="foo/barness", width_field="width", height_field="height")
        name, path, args, kwargs = field.deconstruct()
        self.assertEqual(path, "django.db.models.ImageField")
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {"upload_to": "foo/barness", "width_field": "width", "height_field": "height"}) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:8,代码来源:tests.py


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