當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。