Python django.db.models 模块,BinaryField() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.db.models.BinaryField()

项目:django-twilio-tfa    作者:rtindru    | 项目源码 | 文件源码
def test_serializer_binary_field(self):
        class SomeBinaryModel(models.Model):
            bb = models.BinaryField()
            bb_empty = models.BinaryField()

        instance = SomeBinaryModel(bb=b'some binary data')

        serialized = utils.serialize_instance(instance)
        deserialized = utils.deserialize_instance(SomeBinaryModel, serialized)

        self.assertEqual(serialized['bb'], 'c29tZSBiaW5hcnkgZGF0YQ==')
        self.assertEqual(serialized['bb_empty'], '')
        self.assertEqual(deserialized.bb, b'some binary data')
        self.assertEqual(deserialized.bb_empty, b'')
项目:python-ibmdb-django    作者:ibmdb    | 项目源码 | 文件源码
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, []
项目:maas    作者:maas    | 项目源码 | 文件源码
def test_is_BinaryField(self):
        self.assertIsInstance(EditableBinaryField(), BinaryField)
项目:Provo-Housing-Database    作者:marcopete5    | 项目源码 | 文件源码
def test_serializer_binary_field(self):
        class SomeBinaryModel(models.Model):
            bb = models.BinaryField()
            bb_empty = models.BinaryField()

        instance = SomeBinaryModel(bb=b'some binary data')

        serialized = utils.serialize_instance(instance)
        deserialized = utils.deserialize_instance(SomeBinaryModel, serialized)

        self.assertEqual(serialized['bb'], 'c29tZSBiaW5hcnkgZGF0YQ==')
        self.assertEqual(serialized['bb_empty'], '')
        self.assertEqual(deserialized.bb, b'some binary data')
        self.assertEqual(deserialized.bb_empty, b'')
项目:otree_custom_models    作者:WZBSocialScienceCenter    | 项目源码 | 文件源码
def inspect_field_names(Model):
    # filter out BinaryField, because it's not useful for CSV export or
    # live results. could be very big, and causes problems with utf-8 export

    # I tried .get_fields() instead of .fields, but that method returns
    # fields that cause problems, like saying group has an attribute 'player'
    return [f.name for f in Model._meta.fields
            if not isinstance(f, BinaryField)]