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


Python models.BinaryField方法代码示例

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


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

示例1: column_sql

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BinaryField [as 别名]
def column_sql(self, model, field, include_default=True):
        db_parameter = field.db_parameters(connection=self.connection)
        sql = db_parameter['type']
        if sql is None:
            return None, None
        if include_default:
            if (field.default is not None) and field.has_default():
                value = field.get_default()
                value = self.prepare_default(value)
                if( djangoVersion[0:2] >= ( 1, 8 ) ):
                    if isinstance(field,models.BinaryField ):
                        if (value=="''"):
                            value  = 'EMPTY_BLOB()'
                        else:                       
                            value='blob( %s'  %value + ')'
                                            
                sql += " DEFAULT %s" % value
            else:
                field.default = None
        if not field.null:
            sql += " NOT NULL"
        if field.primary_key:
            sql += " PRIMARY KEY"
        elif field.unique:
            sql += " UNIQUE"
        tablespace = field.db_tablespace or model._meta.db_tablespace
        if tablespace and field.unique:
            sql += " %s" % self.connection.ops.tablespace_sql(tablespace, inline=True)

        return sql, [] 
开发者ID:ibmdb,项目名称:python-ibmdb-django,代码行数:32,代码来源:schemaEditor.py

示例2: test_binary_field

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

示例3: test_add_binaryfield

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BinaryField [as 别名]
def test_add_binaryfield(self):
        """
        Tests the AddField operation on TextField/BinaryField.
        """
        project_state = self.set_up_test_model("test_adbinfl")

        Pony = project_state.apps.get_model("test_adbinfl", "Pony")
        pony = Pony.objects.create(weight=42)

        new_state = self.apply_operations("test_adbinfl", project_state, [
            migrations.AddField(
                "Pony",
                "blob",
                models.BinaryField(default=b"some text"),
            ),
            migrations.AddField(
                "Pony",
                "empty",
                models.BinaryField(default=b""),
            ),
            # If not properly quoted digits would be interpreted as an int.
            migrations.AddField(
                "Pony",
                "digits",
                models.BinaryField(default=b"42"),
            ),
            # Manual quoting is fragile and could trip on quotes. Refs #xyz.
            migrations.AddField(
                "Pony",
                "quotes",
                models.BinaryField(default=b'"\'"'),
            ),
        ])

        Pony = new_state.apps.get_model("test_adbinfl", "Pony")
        pony = Pony.objects.get(pk=pony.pk)
        # SQLite returns buffer/memoryview, cast to bytes for checking.
        self.assertEqual(bytes(pony.blob), b"some text")
        self.assertEqual(bytes(pony.empty), b"")
        self.assertEqual(bytes(pony.digits), b"42")
        self.assertEqual(bytes(pony.quotes), b'"\'"') 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:43,代码来源:test_operations.py

示例4: setUpTestData

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BinaryField [as 别名]
def setUpTestData(cls):
        o = CaseTestModel.objects.create(integer=1, integer2=1, string='1')
        O2OCaseTestModel.objects.create(o2o=o, integer=1)
        FKCaseTestModel.objects.create(fk=o, integer=1)

        o = CaseTestModel.objects.create(integer=2, integer2=3, string='2')
        O2OCaseTestModel.objects.create(o2o=o, integer=2)
        FKCaseTestModel.objects.create(fk=o, integer=2)
        FKCaseTestModel.objects.create(fk=o, integer=3)

        o = CaseTestModel.objects.create(integer=3, integer2=4, string='3')
        O2OCaseTestModel.objects.create(o2o=o, integer=3)
        FKCaseTestModel.objects.create(fk=o, integer=3)
        FKCaseTestModel.objects.create(fk=o, integer=4)

        o = CaseTestModel.objects.create(integer=2, integer2=2, string='2')
        O2OCaseTestModel.objects.create(o2o=o, integer=2)
        FKCaseTestModel.objects.create(fk=o, integer=2)
        FKCaseTestModel.objects.create(fk=o, integer=3)

        o = CaseTestModel.objects.create(integer=3, integer2=4, string='3')
        O2OCaseTestModel.objects.create(o2o=o, integer=3)
        FKCaseTestModel.objects.create(fk=o, integer=3)
        FKCaseTestModel.objects.create(fk=o, integer=4)

        o = CaseTestModel.objects.create(integer=3, integer2=3, string='3')
        O2OCaseTestModel.objects.create(o2o=o, integer=3)
        FKCaseTestModel.objects.create(fk=o, integer=3)
        FKCaseTestModel.objects.create(fk=o, integer=4)

        o = CaseTestModel.objects.create(integer=4, integer2=5, string='4')
        O2OCaseTestModel.objects.create(o2o=o, integer=1)
        FKCaseTestModel.objects.create(fk=o, integer=5)

        # GROUP BY on Oracle fails with TextField/BinaryField; see #24096.
        cls.non_lob_fields = [
            f.name for f in CaseTestModel._meta.get_fields()
            if not (f.is_relation and f.auto_created) and not isinstance(f, (models.BinaryField, models.TextField))
        ] 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:41,代码来源:tests.py

示例5: test_update_binary

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BinaryField [as 别名]
def test_update_binary(self):
        CaseTestModel.objects.update(
            binary=Case(
                # fails on postgresql on Python 2.7 if output_field is not
                # set explicitly
                When(integer=1, then=Value(b'one', output_field=models.BinaryField())),
                When(integer=2, then=Value(b'two', output_field=models.BinaryField())),
                default=Value(b'', output_field=models.BinaryField()),
            ),
        )
        self.assertQuerysetEqual(
            CaseTestModel.objects.all().order_by('pk'),
            [(1, b'one'), (2, b'two'), (3, b''), (2, b'two'), (3, b''), (3, b''), (4, b'')],
            transform=lambda o: (o.integer, six.binary_type(o.binary))
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:17,代码来源:tests.py

示例6: test_binary_field

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BinaryField [as 别名]
def test_binary_field(self):
        field = models.BinaryField()
        name, path, args, kwargs = field.deconstruct()
        self.assertEqual(path, "django.db.models.BinaryField")
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {})
        field = models.BinaryField(editable=True)
        name, path, args, kwargs = field.deconstruct()
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {'editable': True}) 
开发者ID:nesdis,项目名称:djongo,代码行数:12,代码来源:tests.py

示例7: test_editable

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BinaryField [as 别名]
def test_editable(self):
        field = models.BinaryField()
        self.assertIs(field.editable, False)
        field = models.BinaryField(editable=True)
        self.assertIs(field.editable, True)
        field = models.BinaryField(editable=False)
        self.assertIs(field.editable, False) 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:test_binaryfield.py

示例8: test_update_binary

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BinaryField [as 别名]
def test_update_binary(self):
        CaseTestModel.objects.update(
            binary=Case(
                When(integer=1, then=Value(b'one', output_field=models.BinaryField())),
                When(integer=2, then=Value(b'two', output_field=models.BinaryField())),
                default=Value(b'', output_field=models.BinaryField()),
            ),
        )
        self.assertQuerysetEqual(
            CaseTestModel.objects.all().order_by('pk'),
            [(1, b'one'), (2, b'two'), (3, b''), (2, b'two'), (3, b''), (3, b''), (4, b'')],
            transform=lambda o: (o.integer, bytes(o.binary))
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:tests.py

示例9: test_is_BinaryField

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import BinaryField [as 别名]
def test_is_BinaryField(self):
        self.assertIsInstance(EditableBinaryField(), BinaryField) 
开发者ID:maas,项目名称:maas,代码行数:4,代码来源:test_fields.py


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