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