Ticket #399: bigint-patch-2009-12-07.diff
File bigint-patch-2009-12-07.diff, 9.9 KB (added by , 15 years ago) |
---|
-
django/db/models/fields/__init__.py
714 714 defaults.update(kwargs) 715 715 return super(IntegerField, self).formfield(**defaults) 716 716 717 class BigIntegerField(IntegerField): 718 MAX_BIGINT = 9223372036854775807 719 empty_strings_allowed = False 720 def get_internal_type(self): 721 return "BigIntegerField" 722 723 def get_db_prep_save(self, value): 724 value = long(value) 725 if value > BigIntegerField.MAX_BIGINT or value < -BigIntegerField.MAX_BIGINT - 1: 726 raise ValueError("Value is to small/large to fit this field") 727 return super(BigIntegerField, self).get_db_prep_save(value) 728 729 def formfield(self, **kwargs): 730 defaults = {'min_value': -BigIntegerField.MAX_BIGINT - 1, 731 'max_value': BigIntegerField.MAX_BIGINT} 732 defaults.update(kwargs) 733 return super(BigIntegerField, self).formfield(**defaults) 734 735 717 736 class IPAddressField(Field): 718 737 empty_strings_allowed = False 719 738 def __init__(self, *args, **kwargs): -
django/db/backends/postgresql/introspection.py
4 4 # Maps type codes to Django Field types. 5 5 data_types_reverse = { 6 6 16: 'BooleanField', 7 20: 'BigIntegerField', 7 8 21: 'SmallIntegerField', 8 9 23: 'IntegerField', 9 10 25: 'TextField', -
django/db/backends/postgresql/creation.py
18 18 'FilePathField': 'varchar(%(max_length)s)', 19 19 'FloatField': 'double precision', 20 20 'IntegerField': 'integer', 21 'BigIntegerField': 'bigint', 21 22 'IPAddressField': 'inet', 22 23 'NullBooleanField': 'boolean', 23 24 'OneToOneField': 'integer', -
django/db/backends/sqlite3/introspection.py
16 16 'smallinteger': 'SmallIntegerField', 17 17 'int': 'IntegerField', 18 18 'integer': 'IntegerField', 19 'bigint': 'BigIntegerField', 19 20 'integer unsigned': 'PositiveIntegerField', 20 21 'decimal': 'DecimalField', 21 22 'real': 'FloatField', -
django/db/backends/sqlite3/creation.py
19 19 'FilePathField': 'varchar(%(max_length)s)', 20 20 'FloatField': 'real', 21 21 'IntegerField': 'integer', 22 'BigIntegerField': 'bigint', 22 23 'IPAddressField': 'char(15)', 23 24 'NullBooleanField': 'bool', 24 25 'OneToOneField': 'integer', -
django/db/backends/mysql/introspection.py
17 17 FIELD_TYPE.FLOAT: 'FloatField', 18 18 FIELD_TYPE.INT24: 'IntegerField', 19 19 FIELD_TYPE.LONG: 'IntegerField', 20 FIELD_TYPE.LONGLONG: ' IntegerField',20 FIELD_TYPE.LONGLONG: 'BigIntegerField', 21 21 FIELD_TYPE.SHORT: 'IntegerField', 22 22 FIELD_TYPE.STRING: 'CharField', 23 23 FIELD_TYPE.TIMESTAMP: 'DateTimeField', -
django/db/backends/mysql/creation.py
18 18 'FilePathField': 'varchar(%(max_length)s)', 19 19 'FloatField': 'double precision', 20 20 'IntegerField': 'integer', 21 'BigIntegerField': 'bigint', 21 22 'IPAddressField': 'char(15)', 22 23 'NullBooleanField': 'bool', 23 24 'OneToOneField': 'integer', … … 63 64 field.rel.to._meta.db_table, field.rel.to._meta.pk.column) 64 65 ] 65 66 return table_output, deferred 66 67 No newline at end of file 67 -
django/db/backends/oracle/creation.py
27 27 'FilePathField': 'NVARCHAR2(%(max_length)s)', 28 28 'FloatField': 'DOUBLE PRECISION', 29 29 'IntegerField': 'NUMBER(11)', 30 'BigIntegerField': 'NUMBER(19)', 30 31 'IPAddressField': 'VARCHAR2(15)', 31 32 'NullBooleanField': 'NUMBER(1) CHECK ((%(qn_column)s IN (0,1)) OR (%(qn_column)s IS NULL))', 32 33 'OneToOneField': 'NUMBER(11)', -
django/contrib/admin/options.py
41 41 'form_class': forms.SplitDateTimeField, 42 42 'widget': widgets.AdminSplitDateTime 43 43 }, 44 models.DateField: {'widget': widgets.AdminDateWidget}, 45 models.TimeField: {'widget': widgets.AdminTimeWidget}, 46 models.TextField: {'widget': widgets.AdminTextareaWidget}, 47 models.URLField: {'widget': widgets.AdminURLFieldWidget}, 48 models.IntegerField: {'widget': widgets.AdminIntegerFieldWidget}, 49 models.CharField: {'widget': widgets.AdminTextInputWidget}, 50 models.ImageField: {'widget': widgets.AdminFileWidget}, 51 models.FileField: {'widget': widgets.AdminFileWidget}, 44 models.DateField: {'widget': widgets.AdminDateWidget}, 45 models.TimeField: {'widget': widgets.AdminTimeWidget}, 46 models.TextField: {'widget': widgets.AdminTextareaWidget}, 47 models.URLField: {'widget': widgets.AdminURLFieldWidget}, 48 models.IntegerField: {'widget': widgets.AdminIntegerFieldWidget}, 49 models.BigIntegerField: {'widget': widgets.AdminIntegerFieldWidget}, 50 models.CharField: {'widget': widgets.AdminTextInputWidget}, 51 models.ImageField: {'widget': widgets.AdminFileWidget}, 52 models.FileField: {'widget': widgets.AdminFileWidget}, 52 53 } 53 54 54 55 -
tests/regressiontests/model_fields/tests.py
6 6 from django.db import models 7 7 from django.core.exceptions import ValidationError 8 8 9 from models import Foo, Bar, Whiz, BigD, BigS, Image 9 from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt 10 10 11 11 try: 12 12 from decimal import Decimal … … 144 144 bs = BigS.objects.create(s = 'slug'*50) 145 145 bs = BigS.objects.get(pk=bs.pk) 146 146 self.assertEqual(bs.s, 'slug'*50) 147 148 class BigIntegerFieldTests(django.test.TestCase): 149 def test_existence(self): 150 self.assertEqual(len(BigInt.objects.all()), 0) 151 152 def test_limits(self): 153 self.assertRaises(ValueError, BigInt(value = 9223372036854775809111111111111111111).save) 154 self.assertRaises(ValueError, BigInt(value = -9223372036854775809111111111111111111).save) 155 self.assertRaises(ValueError, BigInt(value = 9223372036854775808).save) 156 self.assertRaises(ValueError, BigInt(value = -9223372036854775809).save) 157 self.assertEqual(BigInt(value = -9223372036854775808).save(), None) 158 self.assertEqual(BigInt(value = 9223372036854775807).save(), None) 159 self.assertEqual(BigInt(value = 0).save(), None) 160 161 def test_types(self): 162 b = BigInt(value = 0) 163 self.assertTrue(isinstance(b.value, (int, long))) 164 b.save() 165 self.assertTrue(isinstance(b.value, (int, long))) 166 b = BigInt.objects.all()[0] 167 self.assertTrue(isinstance(b.value, (int, long))) 168 169 def test_coercing(self): 170 b = BigInt(value = 10) 171 b.save() 172 self.assertEqual(b.value, 10) 173 self.assertEqual(unicode(b), unicode(10)) -
tests/regressiontests/model_fields/models.py
51 51 class BigS(models.Model): 52 52 s = models.SlugField(max_length=255) 53 53 54 class BigInt(models.Model): 55 value = models.BigIntegerField() 54 56 57 def __unicode__(self): 58 return unicode(self.value) 59 55 60 ############################################################################### 56 61 # ImageField 57 62 -
docs/ref/models/fields.txt
641 641 An integer. The admin represents this as an ``<input type="text">`` (a 642 642 single-line input). 643 643 644 ``bigintegerfield`` 645 ~~~~~~~~~~~~~~~~ 646 647 .. class:: BigIntegerField([**options]) 648 649 A big integer. The admin represents this as an ``<input type="text">`` 650 (a single-line input). 651 652 a 64 bit type like an ``integerfield``, except that it fits numbers from 653 -9223372036854775808 to 9223372036854775807 654 655 644 656 ``IPAddressField`` 645 657 ------------------ 646 658