Ticket #2417: binaryfield.patch

File binaryfield.patch, 4.1 KB (added by scanner@…, 18 years ago)

A small patch to add a BinaryField type directly to django. Supports small'ish binary fields.

  • django/db/models/manipulators.py

     
    278278    if isinstance(field_list[0].rel, ManyToOneRel):
    279279        kwargs = {'%s__%s__iexact' % (field_name_list[0], field_list[0].rel.field_name): field_data}
    280280    else:
    281         kwargs = {'%s__iexact' % field_name_list[0]: field_data}
     281        kwargs = {'%s__exact' % field_name_list[0]: field_data}
    282282    for f in field_list[1:]:
    283283        # This is really not going to work for fields that have different
    284284        # form fields, e.g. DateTime.
     
    291291        if isinstance(f.rel, ManyToOneRel):
    292292            kwargs['%s__pk' % f.name] = field_val
    293293        else:
    294             kwargs['%s__iexact' % f.name] = field_val
     294            kwargs['%s__exact' % f.name] = field_val
    295295    try:
    296296        old_obj = self.manager.get(**kwargs)
    297297    except ObjectDoesNotExist:
  • django/db/models/fields/__init__.py

     
    385385                raise validators.ValidationError, gettext_lazy("This field cannot be null.")
    386386        return str(value)
    387387
     388class BinaryField(CharField):
     389    """Sometimes we have fields that need to store a small amount of binary
     390    data. This is different then a varchar on postgresql at least because it
     391    will not allow fields that are just nul bytes.
     392    """
     393    def get_manipulator_field_objs(self):
     394        # XXX We should probably use a better form field for this. Like
     395        # XXX something that can grok colon-separated hexlify.
     396        #
     397        return [django.forms.TextField]
     398
     399
    388400# TODO: Maybe move this into contrib, because it's specialized.
    389401class CommaSeparatedIntegerField(CharField):
    390402    def get_manipulator_field_objs(self):
  • django/db/backends/ado_mssql/creation.py

     
    11DATA_TYPES = {
    22    'AutoField':         'int IDENTITY (1, 1)',
     3    'BinaryField':       'varbinary(%(maxlength)s)',
    34    'BooleanField':      'bit',
    45    'CharField':         'varchar(%(maxlength)s)',
    56    'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
  • django/db/backends/postgresql/creation.py

     
    44# If a column type is set to None, it won't be included in the output.
    55DATA_TYPES = {
    66    'AutoField':         'serial',
     7    'BinaryField':       'bytea',
    78    'BooleanField':      'boolean',
    89    'CharField':         'varchar(%(maxlength)s)',
    910    'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
  • django/db/backends/sqlite3/creation.py

     
    33# schema inspection is more useful.
    44DATA_TYPES = {
    55    'AutoField':                    'integer',
     6    'BinaryField':                  'BLOB',
    67    'BooleanField':                 'bool',
    78    'CharField':                    'varchar(%(maxlength)s)',
    89    'CommaSeparatedIntegerField':   'varchar(%(maxlength)s)',
  • django/db/backends/mysql/creation.py

     
    44# If a column type is set to None, it won't be included in the output.
    55DATA_TYPES = {
    66    'AutoField':         'integer AUTO_INCREMENT',
     7    'BinaryField':       'varbinary(%(maxlength)s)',
    78    'BooleanField':      'bool',
    89    'CharField':         'varchar(%(maxlength)s)',
    910    'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
Back to Top