diff options
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/mysql/creation.py | 1 | ||||
| -rw-r--r-- | django/db/backends/oracle/creation.py | 1 | ||||
| -rw-r--r-- | django/db/backends/postgresql_psycopg2/creation.py | 1 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/creation.py | 1 | ||||
| -rw-r--r-- | django/db/models/fields/__init__.py | 27 | ||||
| -rw-r--r-- | django/utils/six.py | 4 |
6 files changed, 35 insertions, 0 deletions
diff --git a/django/db/backends/mysql/creation.py b/django/db/backends/mysql/creation.py index 01efe8d35b..3a57c29479 100644 --- a/django/db/backends/mysql/creation.py +++ b/django/db/backends/mysql/creation.py @@ -7,6 +7,7 @@ class DatabaseCreation(BaseDatabaseCreation): # If a column type is set to None, it won't be included in the output. data_types = { 'AutoField': 'integer AUTO_INCREMENT', + 'BinaryField': 'longblob', 'BooleanField': 'bool', 'CharField': 'varchar(%(max_length)s)', 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py index 1cc3957232..aaca74e8d1 100644 --- a/django/db/backends/oracle/creation.py +++ b/django/db/backends/oracle/creation.py @@ -17,6 +17,7 @@ class DatabaseCreation(BaseDatabaseCreation): data_types = { 'AutoField': 'NUMBER(11)', + 'BinaryField': 'BLOB', 'BooleanField': 'NUMBER(1) CHECK (%(qn_column)s IN (0,1))', 'CharField': 'NVARCHAR2(%(max_length)s)', 'CommaSeparatedIntegerField': 'VARCHAR2(%(max_length)s)', diff --git a/django/db/backends/postgresql_psycopg2/creation.py b/django/db/backends/postgresql_psycopg2/creation.py index d977939f41..b19926b440 100644 --- a/django/db/backends/postgresql_psycopg2/creation.py +++ b/django/db/backends/postgresql_psycopg2/creation.py @@ -11,6 +11,7 @@ class DatabaseCreation(BaseDatabaseCreation): # If a column type is set to None, it won't be included in the output. data_types = { 'AutoField': 'serial', + 'BinaryField': 'bytea', 'BooleanField': 'boolean', 'CharField': 'varchar(%(max_length)s)', 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', diff --git a/django/db/backends/sqlite3/creation.py b/django/db/backends/sqlite3/creation.py index 9dacac72e1..c90a697e35 100644 --- a/django/db/backends/sqlite3/creation.py +++ b/django/db/backends/sqlite3/creation.py @@ -9,6 +9,7 @@ class DatabaseCreation(BaseDatabaseCreation): # schema inspection is more useful. data_types = { 'AutoField': 'integer', + 'BinaryField': 'BLOB', 'BooleanField': 'bool', 'CharField': 'varchar(%(max_length)s)', 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 2702876397..8302aaceaa 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1291,3 +1291,30 @@ class URLField(CharField): } defaults.update(kwargs) return super(URLField, self).formfield(**defaults) + +class BinaryField(Field): + description = _("Raw binary data") + + def __init__(self, *args, **kwargs): + kwargs['editable'] = False + super(BinaryField, self).__init__(*args, **kwargs) + if self.max_length is not None: + self.validators.append(validators.MaxLengthValidator(self.max_length)) + + def get_internal_type(self): + return "BinaryField" + + def get_default(self): + if self.has_default() and not callable(self.default): + return self.default + default = super(BinaryField, self).get_default() + if default == '': + return b'' + return default + + def get_db_prep_value(self, value, connection, prepared=False): + value = super(BinaryField, self + ).get_db_prep_value(value, connection, prepared) + if value is not None: + return connection.Database.Binary(value) + return value diff --git a/django/utils/six.py b/django/utils/six.py index b93dc5b164..208c5c1112 100644 --- a/django/utils/six.py +++ b/django/utils/six.py @@ -394,10 +394,14 @@ if PY3: _iterlists = "lists" _assertRaisesRegex = "assertRaisesRegex" _assertRegex = "assertRegex" + memoryview = memoryview else: _iterlists = "iterlists" _assertRaisesRegex = "assertRaisesRegexp" _assertRegex = "assertRegexpMatches" + # memoryview and buffer are not stricly equivalent, but should be fine for + # django core usage (mainly BinaryField) + memoryview = buffer def iterlists(d): |
