Ticket #399: kmt-bigint.diff

File kmt-bigint.diff, 14.2 KB (added by kmtracey, 6 years ago)
  • django/db/models/fields/__init__.py

     
    732732        defaults.update(kwargs)
    733733        return super(IntegerField, self).formfield(**defaults)
    734734
     735class BigIntegerField(IntegerField):
     736    empty_strings_allowed = False
     737    description = ugettext_lazy("Big (8 byte) integer")
     738    MAX_BIGINT = 9223372036854775807
     739    def get_internal_type(self):
     740        return "BigIntegerField"
     741
     742    def formfield(self, **kwargs):
     743        defaults = {'min_value': -BigIntegerField.MAX_BIGINT - 1,
     744                    'max_value': BigIntegerField.MAX_BIGINT}
     745        defaults.update(kwargs)
     746        return super(BigIntegerField, self).formfield(**defaults)
     747
    735748class IPAddressField(Field):
    736749    empty_strings_allowed = False
    737750    description = ugettext_lazy("IP address")
  • django/db/backends/postgresql/introspection.py

     
    44    # Maps type codes to Django Field types.
    55    data_types_reverse = {
    66        16: 'BooleanField',
     7        20: 'BigIntegerField',
    78        21: 'SmallIntegerField',
    89        23: 'IntegerField',
    910        25: 'TextField',
  • django/db/backends/postgresql/creation.py

     
    1818        'FilePathField':     'varchar(%(max_length)s)',
    1919        'FloatField':        'double precision',
    2020        'IntegerField':      'integer',
     21        'BigIntegerField':   'bigint',
    2122        'IPAddressField':    'inet',
    2223        'NullBooleanField':  'boolean',
    2324        'OneToOneField':     'integer',
  • django/db/backends/sqlite3/introspection.py

     
    1616        'smallinteger': 'SmallIntegerField',
    1717        'int': 'IntegerField',
    1818        'integer': 'IntegerField',
     19        'bigint': 'BigIntegerField',
    1920        'integer unsigned': 'PositiveIntegerField',
    2021        'decimal': 'DecimalField',
    2122        'real': 'FloatField',
  • django/db/backends/sqlite3/creation.py

     
    1919        'FilePathField':                'varchar(%(max_length)s)',
    2020        'FloatField':                   'real',
    2121        'IntegerField':                 'integer',
     22        'BigIntegerField':              'bigint',
    2223        'IPAddressField':               'char(15)',
    2324        'NullBooleanField':             'bool',
    2425        'OneToOneField':                'integer',
  • django/db/backends/mysql/introspection.py

     
    1717        FIELD_TYPE.FLOAT: 'FloatField',
    1818        FIELD_TYPE.INT24: 'IntegerField',
    1919        FIELD_TYPE.LONG: 'IntegerField',
    20         FIELD_TYPE.LONGLONG: 'IntegerField',
     20        FIELD_TYPE.LONGLONG: 'BigIntegerField',
    2121        FIELD_TYPE.SHORT: 'IntegerField',
    2222        FIELD_TYPE.STRING: 'CharField',
    2323        FIELD_TYPE.TIMESTAMP: 'DateTimeField',
  • django/db/backends/mysql/creation.py

     
    1818        'FilePathField':     'varchar(%(max_length)s)',
    1919        'FloatField':        'double precision',
    2020        'IntegerField':      'integer',
     21        'BigIntegerField':   'bigint',
    2122        'IPAddressField':    'char(15)',
    2223        'NullBooleanField':  'bool',
    2324        'OneToOneField':     'integer',
  • django/db/backends/oracle/introspection.py

     
    2929    def get_field_type(self, data_type, description):
    3030        # If it's a NUMBER with scale == 0, consider it an IntegerField
    3131        if data_type == cx_Oracle.NUMBER and description[5] == 0:
    32             return 'IntegerField'
     32            if description[4] > 11:
     33                return 'BigIntegerField'
     34            else:
     35                return 'IntegerField'
    3336        else:
    3437            return super(DatabaseIntrospection, self).get_field_type(
    3538                data_type, description)
  • django/db/backends/oracle/creation.py

     
    2727        'FilePathField':                'NVARCHAR2(%(max_length)s)',
    2828        'FloatField':                   'DOUBLE PRECISION',
    2929        'IntegerField':                 'NUMBER(11)',
     30        'BigIntegerField':              'NUMBER(19)',
    3031        'IPAddressField':               'VARCHAR2(15)',
    3132        'NullBooleanField':             'NUMBER(1) CHECK ((%(qn_column)s IN (0,1)) OR (%(qn_column)s IS NULL))',
    3233        'OneToOneField':                'NUMBER(11)',
  • django/contrib/admin/options.py

     
    4242        'form_class': forms.SplitDateTimeField,
    4343        'widget': widgets.AdminSplitDateTime
    4444    },
    45     models.DateField:    {'widget': widgets.AdminDateWidget},
    46     models.TimeField:    {'widget': widgets.AdminTimeWidget},
    47     models.TextField:    {'widget': widgets.AdminTextareaWidget},
    48     models.URLField:     {'widget': widgets.AdminURLFieldWidget},
    49     models.IntegerField: {'widget': widgets.AdminIntegerFieldWidget},
    50     models.CharField:    {'widget': widgets.AdminTextInputWidget},
    51     models.ImageField:   {'widget': widgets.AdminFileWidget},
    52     models.FileField:    {'widget': widgets.AdminFileWidget},
     45    models.DateField:       {'widget': widgets.AdminDateWidget},
     46    models.TimeField:       {'widget': widgets.AdminTimeWidget},
     47    models.TextField:       {'widget': widgets.AdminTextareaWidget},
     48    models.URLField:        {'widget': widgets.AdminURLFieldWidget},
     49    models.IntegerField:    {'widget': widgets.AdminIntegerFieldWidget},
     50    models.BigIntegerField: {'widget': widgets.AdminIntegerFieldWidget},
     51    models.CharField:       {'widget': widgets.AdminTextInputWidget},
     52    models.ImageField:      {'widget': widgets.AdminFileWidget},
     53    models.FileField:       {'widget': widgets.AdminFileWidget},
    5354}
    5455
    5556
  • tests/modeltests/model_forms/models.py

     
    1313from django.db import models
    1414from django.core.files.storage import FileSystemStorage
    1515
    16 # Python 2.3 doesn't have sorted()
    17 try:
    18     sorted
    19 except NameError:
    20     from django.utils.itercompat import sorted
    21 
    2216temp_storage_dir = tempfile.mkdtemp()
    2317temp_storage = FileSystemStorage(temp_storage_dir)
    2418
     
    201195    def __unicode__(self):
    202196        return self.name
    203197
     198class BigInt(models.Model):
     199    biggie = models.BigIntegerField()
     200
     201    def __unicode__(self):
     202        return unicode(self.biggie)
     203
    204204__test__ = {'API_TESTS': """
    205205>>> from django import forms
    206206>>> from django.forms.models import ModelForm, model_to_dict
     
    11451145# Delete the current file since this is not done by Django.
    11461146>>> instance.file.delete()
    11471147>>> instance.delete()
     1148
     1149# BigIntegerField ################################################################
     1150>>> class BigIntForm(forms.ModelForm):
     1151...     class Meta:
     1152...         model = BigInt
     1153...
     1154>>> bif = BigIntForm({'biggie': '-9223372036854775808'})
     1155>>> bif.is_valid()
     1156True
     1157>>> bif = BigIntForm({'biggie': '-9223372036854775809'})
     1158>>> bif.is_valid()
     1159False
     1160>>> bif.errors
     1161{'biggie': [u'Ensure this value is greater than or equal to -9223372036854775808.']}
     1162>>> bif = BigIntForm({'biggie': '9223372036854775807'})
     1163>>> bif.is_valid()
     1164True
     1165>>> bif = BigIntForm({'biggie': '9223372036854775808'})
     1166>>> bif.is_valid()
     1167False
     1168>>> bif.errors
     1169{'biggie': [u'Ensure this value is less than or equal to 9223372036854775807.']}
    11481170"""}
    11491171
    11501172if test_images:
  • tests/regressiontests/model_fields/tests.py

     
    66from django.db import models
    77from django.core.exceptions import ValidationError
    88
    9 from models import Foo, Bar, Whiz, BigD, BigS, Image
     9from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt
    1010
    1111try:
    1212    from decimal import Decimal
     
    144144        bs = BigS.objects.create(s = 'slug'*50)
    145145        bs = BigS.objects.get(pk=bs.pk)
    146146        self.assertEqual(bs.s, 'slug'*50)
     147
     148class BigIntegerFieldTests(django.test.TestCase):
     149    def test_limits(self):
     150        # Ensure that values that are right at the limits can be saved
     151        # and then retrieved without corruption.
     152        maxval = 9223372036854775807
     153        minval = -maxval - 1
     154        BigInt.objects.create(value=maxval)
     155        qs = BigInt.objects.filter(value__gte=maxval)
     156        self.assertEqual(qs.count(), 1)
     157        self.assertEqual(qs[0].value, maxval)
     158        BigInt.objects.create(value=minval)
     159        qs = BigInt.objects.filter(value__lte=minval)
     160        self.assertEqual(qs.count(), 1)
     161        self.assertEqual(qs[0].value, minval)
     162
     163    def test_types(self):
     164        b = BigInt(value = 0)
     165        self.assertTrue(isinstance(b.value, (int, long)))
     166        b.save()
     167        self.assertTrue(isinstance(b.value, (int, long)))
     168        b = BigInt.objects.all()[0]
     169        self.assertTrue(isinstance(b.value, (int, long)))
     170
     171    def test_coercing(self):
     172        BigInt.objects.create(value ='10')
     173        b = BigInt.objects.get(value = '10')
     174        self.assertEqual(b.value, 10)
     175
  • tests/regressiontests/model_fields/models.py

     
    5151class BigS(models.Model):
    5252    s = models.SlugField(max_length=255)
    5353
     54class BigInt(models.Model):
     55    value = models.BigIntegerField()
     56    null_value = models.BigIntegerField(null = True, blank = True)
    5457
    5558###############################################################################
    5659# ImageField
  • tests/regressiontests/introspection/tests.py

     
    7777        cursor = connection.cursor()
    7878        desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table)
    7979        self.assertEqual([datatype(r[1], r) for r in desc],
    80                           ['IntegerField', 'CharField', 'CharField', 'CharField'])
     80                          ['IntegerField', 'CharField', 'CharField', 'CharField', 'BigIntegerField'])
    8181
    8282    # Regression test for #9991 - 'real' types in postgres
    8383    if settings.DATABASE_ENGINE.startswith('postgresql'):
  • tests/regressiontests/introspection/models.py

     
    44    first_name = models.CharField(max_length=30)
    55    last_name = models.CharField(max_length=30)
    66    email = models.EmailField()
     7    facebook_user_id = models.BigIntegerField()
    78
    89    def __unicode__(self):
    910        return u"%s %s" % (self.first_name, self.last_name)
  • docs/topics/forms/modelforms.txt

     
    4646    ===============================  ========================================
    4747    ``AutoField``                    Not represented in the form
    4848
     49    ``BigIntegerField``              ``IntegerField`` with ``min_value`` set
     50                                     to -9223372036854775808 and ``max_value``
     51                                     set to 9223372036854775807.
     52
    4953    ``BooleanField``                 ``BooleanField``
    5054
    5155    ``CharField``                    ``CharField`` with ``max_length`` set to
     
    108112    The ``FloatField`` form field and ``DecimalField`` model and form fields
    109113    are new in Django 1.0.
    110114
     115.. versionadded:: 1.2
     116    The ``BigIntegerField`` is new in Django 1.2.
     117
     118
    111119As you might expect, the ``ForeignKey`` and ``ManyToManyField`` model field
    112120types are special cases:
    113121
  • docs/ref/models/fields.txt

     
    299299primary key field will automatically be added to your model if you don't specify
    300300otherwise. See :ref:`automatic-primary-key-fields`.
    301301
     302``BigIntegerField``
     303-------------------
     304
     305.. versionadded:: 1.2
     306
     307.. class:: BigIntegerField([**options])
     308
     309A 64 bit integer, much like an :class:`IntegerField` except that it is
     310guaranteed to fit numbers from -9223372036854775808 to 9223372036854775807. The
     311admin represents this as an ``<input type="text">`` (a single-line input).
     312 
     313
    302314``BooleanField``
    303315----------------
    304316
Back to Top