mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #399: Added big integer field. Thanks to Tomáš Kopeček for persistently maintaining a patch for this.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11887 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
fd4cc65baf
commit
5bd63663a9
20 changed files with 125 additions and 18 deletions
|
@ -6,7 +6,7 @@ from django import forms
|
|||
from django.db import models
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from models import Foo, Bar, Whiz, BigD, BigS, Image
|
||||
from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt
|
||||
|
||||
try:
|
||||
from decimal import Decimal
|
||||
|
@ -144,3 +144,32 @@ class SlugFieldTests(django.test.TestCase):
|
|||
bs = BigS.objects.create(s = 'slug'*50)
|
||||
bs = BigS.objects.get(pk=bs.pk)
|
||||
self.assertEqual(bs.s, 'slug'*50)
|
||||
|
||||
class BigIntegerFieldTests(django.test.TestCase):
|
||||
def test_limits(self):
|
||||
# Ensure that values that are right at the limits can be saved
|
||||
# and then retrieved without corruption.
|
||||
maxval = 9223372036854775807
|
||||
minval = -maxval - 1
|
||||
BigInt.objects.create(value=maxval)
|
||||
qs = BigInt.objects.filter(value__gte=maxval)
|
||||
self.assertEqual(qs.count(), 1)
|
||||
self.assertEqual(qs[0].value, maxval)
|
||||
BigInt.objects.create(value=minval)
|
||||
qs = BigInt.objects.filter(value__lte=minval)
|
||||
self.assertEqual(qs.count(), 1)
|
||||
self.assertEqual(qs[0].value, minval)
|
||||
|
||||
def test_types(self):
|
||||
b = BigInt(value = 0)
|
||||
self.assertTrue(isinstance(b.value, (int, long)))
|
||||
b.save()
|
||||
self.assertTrue(isinstance(b.value, (int, long)))
|
||||
b = BigInt.objects.all()[0]
|
||||
self.assertTrue(isinstance(b.value, (int, long)))
|
||||
|
||||
def test_coercing(self):
|
||||
BigInt.objects.create(value ='10')
|
||||
b = BigInt.objects.get(value = '10')
|
||||
self.assertEqual(b.value, 10)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue