Ticket #8316: db-mysqltypeissue.2.diff

File db-mysqltypeissue.2.diff, 5.5 KB (added by julianb, 7 years ago)

v2

  • django/db/backends/mysql/creation.py

     
    1919        'FloatField':        'double precision',
    2020        'IntegerField':      'integer',
    2121        'IPAddressField':    'char(15)',
     22        'KeyField':          'integer',
    2223        'NullBooleanField':  'bool',
    23         'OneToOneField':     'integer',
    2424        'PhoneNumberField':  'varchar(20)',
    2525        'PositiveIntegerField': 'integer UNSIGNED',
    2626        'PositiveSmallIntegerField': 'smallint UNSIGNED',
  • django/db/backends/oracle/creation.py

     
    2828        'FloatField':                   'DOUBLE PRECISION',
    2929        'IntegerField':                 'NUMBER(11)',
    3030        'IPAddressField':               'VARCHAR2(15)',
     31        'KeyField':                     'NUMBER(11)',
    3132        'NullBooleanField':             'NUMBER(1) CHECK ((%(qn_column)s IN (0,1)) OR (%(qn_column)s IS NULL))',
    32         'OneToOneField':                'NUMBER(11)',
    3333        'PhoneNumberField':             'VARCHAR2(20)',
    3434        'PositiveIntegerField':         'NUMBER(11) CHECK (%(qn_column)s >= 0)',
    3535        'PositiveSmallIntegerField':    'NUMBER(11) CHECK (%(qn_column)s >= 0)',
  • django/db/backends/postgresql/creation.py

     
    1919        'FloatField':        'double precision',
    2020        'IntegerField':      'integer',
    2121        'IPAddressField':    'inet',
     22        'KeyField':          'integer',
    2223        'NullBooleanField':  'boolean',
    23         'OneToOneField':     'integer',
    2424        'PhoneNumberField':  'varchar(20)',
    2525        'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
    2626        'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
  • django/db/backends/sqlite3/creation.py

     
    2020        'FloatField':                   'real',
    2121        'IntegerField':                 'integer',
    2222        'IPAddressField':               'char(15)',
     23        'KeyField':                     'integer',
    2324        'NullBooleanField':             'bool',
    24         'OneToOneField':                'integer',
    2525        'PhoneNumberField':             'varchar(20)',
    2626        'PositiveIntegerField':         'integer unsigned',
    2727        'PositiveSmallIntegerField':    'smallint unsigned',
  • django/db/models/fields/__init__.py

     
    808808        defaults.update(kwargs)
    809809        return super(IPAddressField, self).formfield(**defaults)
    810810
     811class KeyField(Field):
     812    empty_strings_allowed = False
     813    def get_db_prep_value(self, value):
     814        if value is None:
     815            return None
     816        return int(value)
     817
     818    def get_manipulator_field_objs(self):
     819        return [oldforms.IntegerField]
     820
     821    def get_internal_type(self):
     822        return "KeyField"
     823
     824    def formfield(self, **kwargs):
     825        defaults = {'form_class': forms.IntegerField}
     826        defaults.update(kwargs)
     827        return super(KeyField, self).formfield(**defaults)
     828
    811829class NullBooleanField(Field):
    812830    empty_strings_allowed = False
    813831    def __init__(self, *args, **kwargs):
  • django/db/models/fields/related.py

     
    11from django.db import connection, transaction
    22from django.db.models import signals, get_model
    3 from django.db.models.fields import AutoField, Field, IntegerField, PositiveIntegerField, PositiveSmallIntegerField, FieldDoesNotExist
     3from django.db.models.fields import AutoField, Field, KeyField, PositiveIntegerField, PositiveSmallIntegerField, FieldDoesNotExist
    44from django.db.models.related import RelatedObject
    55from django.db.models.query import QuerySet
    66from django.db.models.query_utils import QueryWrapper
     
    710710    def db_type(self):
    711711        # The database column type of a ForeignKey is the column type
    712712        # of the field to which it points. An exception is if the ForeignKey
    713         # points to an AutoField/PositiveIntegerField/PositiveSmallIntegerField,
    714         # in which case the column type is simply that of an IntegerField.
     713        # points to an AutoField, in which case the column type is simply that
     714        # of a KeyField.
    715715        rel_field = self.rel.get_related_field()
    716         if isinstance(rel_field, (AutoField, PositiveIntegerField, PositiveSmallIntegerField)):
    717             return IntegerField().db_type()
     716        if isinstance(rel_field, AutoField):
     717            return KeyField().db_type()
    718718        return rel_field.db_type()
    719719
    720720class OneToOneField(ForeignKey):
Back to Top