Ticket #399: patch.diff

File patch.diff, 9.2 KB (added by Tomáš Kopeček, 17 years ago)

Updated, added constraint checking

  • django/db/models/fields/__init__.py

     
    11import datetime
    22import os
     3import sys
    34import time
    45try:
    56    import decimal
     
    868869        defaults.update(kwargs)
    869870        return super(IntegerField, self).formfield(**defaults)
    870871
     872class BigIntegerField(IntegerField):
     873    empty_strings_allowed = False
     874    def get_manipulator_field_objs(self):
     875        return [oldforms.BigIntegerField]
     876
     877    def get_db_prep_save(self, value):
     878        if value > sys.maxint or value < -sys.maxint - 1:
     879            raise ValueError("Value is so small/large to fit to field")
     880        return super(BigIntegerField, self).get_db_prep_save(value)
     881
     882
    871883class IPAddressField(Field):
    872884    empty_strings_allowed = False
    873885    def __init__(self, *args, **kwargs):
  • django/db/backends/ado_mssql/creation.py

     
    1111    'FloatField':        'double precision',
    1212    'ImageField':        'varchar(100)',
    1313    'IntegerField':      'int',
     14    'BigIntegerField':   'bigint',
    1415    'IPAddressField':    'char(15)',
    1516    'NullBooleanField':  'bit',
    1617    'OneToOneField':     'int',
  • django/db/backends/postgresql/introspection.py

     
    7171# Maps type codes to Django Field types.
    7272DATA_TYPES_REVERSE = {
    7373    16: 'BooleanField',
     74    20: 'BigIntegerField',
    7475    21: 'SmallIntegerField',
    7576    23: 'IntegerField',
    7677    25: 'TextField',
  • django/db/backends/postgresql/creation.py

     
    1515    'FloatField':        'double precision',
    1616    'ImageField':        'varchar(100)',
    1717    'IntegerField':      'integer',
     18    'BigIntegerField':   'bigint',
    1819    'IPAddressField':    'inet',
    1920    'NullBooleanField':  'boolean',
    2021    'OneToOneField':     'integer',
  • django/db/backends/sqlite3/introspection.py

     
    6464    'smallinteger': 'SmallIntegerField',
    6565    'int': 'IntegerField',
    6666    'integer': 'IntegerField',
     67    'bigint': 'BigIntegerField',
    6768    'text': 'TextField',
    6869    'char': 'CharField',
    6970    'date': 'DateField',
  • django/db/backends/sqlite3/creation.py

     
    1414    'FloatField':                   'real',
    1515    'ImageField':                   'varchar(100)',
    1616    'IntegerField':                 'integer',
     17    'BigIntegerField':              'bigint',
    1718    'IPAddressField':               'char(15)',
    1819    'NullBooleanField':             'bool',
    1920    'OneToOneField':                'integer',
  • django/db/backends/mysql/introspection.py

     
    8484    FIELD_TYPE.FLOAT: 'FloatField',
    8585    FIELD_TYPE.INT24: 'IntegerField',
    8686    FIELD_TYPE.LONG: 'IntegerField',
    87     FIELD_TYPE.LONGLONG: 'IntegerField',
     87    FIELD_TYPE.LONGLONG: 'BigIntegerField',
    8888    FIELD_TYPE.SHORT: 'IntegerField',
    8989    FIELD_TYPE.STRING: 'CharField',
    9090    FIELD_TYPE.TIMESTAMP: 'DateTimeField',
  • django/db/backends/mysql/creation.py

     
    1515    'FloatField':        'double precision',
    1616    'ImageField':        'varchar(100)',
    1717    'IntegerField':      'integer',
     18    'BigIntegerField':   'bigint',
    1819    'IPAddressField':    'char(15)',
    1920    'NullBooleanField':  'bool',
    2021    'OneToOneField':     'integer',
  • django/db/backends/oracle/creation.py

     
    1818    'FloatField':                   'DOUBLE PRECISION',
    1919    'ImageField':                   'NVARCHAR2(100)',
    2020    'IntegerField':                 'NUMBER(11)',
     21    'BigIntegerField':              'NUMBER(19)',
    2122    'IPAddressField':               'VARCHAR2(15)',
    2223    'NullBooleanField':             'NUMBER(1) CHECK ((%(column)s IN (0,1)) OR (%(column)s IS NULL))',
    2324    'OneToOneField':                'NUMBER(11)',
  • django/db/backends/postgresql_psycopg2/introspection.py

     
    6868# Maps type codes to Django Field types.
    6969DATA_TYPES_REVERSE = {
    7070    16: 'BooleanField',
     71    20: 'BigIntegerField',
    7172    21: 'SmallIntegerField',
    7273    23: 'IntegerField',
    7374    25: 'TextField',
  • django/oldforms/__init__.py

     
    763763        if not 0 <= int(field_data) <= 32767:
    764764            raise validators.CriticalValidationError, ugettext("Enter a whole number between 0 and 32,767.")
    765765
     766class BigIntegerField(IntegerField):
     767    def __init__(self, field_name, length=20, maxlength=None, is_required=False, validator_list=None, member_name=None):
     768        if validator_list is None: validator_list = []
     769        validator_list = [self.isInteger] + validator_list
     770        if member_name is not None:
     771            self.member_name = member_name
     772        IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
     773
    766774class FloatField(TextField):
    767775    def __init__(self, field_name, is_required=False, validator_list=None):
    768776        if validator_list is None: validator_list = []
  • django/contrib/admin/views/doc.py

     
    303303    'ForeignKey'                : _('Integer'),
    304304    'ImageField'                : _('File path'),
    305305    'IntegerField'              : _('Integer'),
     306    'BigIntegerField'           : _('Integer'),
    306307    'IPAddressField'            : _('IP address'),
    307308    'ManyToManyField'           : '',
    308309    'NullBooleanField'          : _('Boolean (Either True, False or None)'),
  • tests/modeltests/field_types/models.py

     
     1"""
     2Tests for field type boundaries
     3"""
     4
     5from django.db import models
     6
     7class BigInt(models.Model):
     8    value = models.BigIntegerField()
     9
     10    def __unicode__(self):
     11        return unicode(self.value)
     12
     13__test__ = {'API_TESTS': """
     14>>> BigInt.objects.all()
     15[]
     16
     17>>> t = BigInt(value = 0)
     18>>> t.save()
     19>>> t.value
     200
     21
     22>>> BigInt.objects.all()
     23[<BigInt: 0>]
     24
     25>>> t = BigInt(value = -9223372036854775808)
     26>>> t.value
     27-9223372036854775808
     28
     29>>> BigInt.objects.all().delete()
     30>>> t.save()
     31>>> BigInt.objects.all()[0]
     32<BigInt: -9223372036854775808>
     33
     34>>> BigInt(value = -9223372036854775809111111111111111111).save()
     35Traceback (most recent call last):
     36...
     37ValueError: Value is so small/large to fit to field
     38
     39>>> BigInt(value = 9223372036854775808).save()
     40Traceback (most recent call last):
     41...
     42ValueError: Value is so small/large to fit to field
     43
     44>>> BigInt(value = 9223372036854775807).save()
     45>>> BigInt.objects.all()
     46[<BigInt: -9223372036854775808>, <BigInt: 9223372036854775807>]
     47"""}
     48
     49def test():
     50    import doctest
     51    doctest.testmod()
  • docs/model-api.txt

     
    126126automatically be added to your model if you don't specify otherwise. See
    127127`Automatic primary key fields`_.
    128128
     129``BigIntegerField``
     130~~~~~~~~~~~~~~~~
     131
     132A big integer.
     133
     134The admin represents this as an ``<input type="text">`` (a single-line input).
     135
     136A 64 bit type like an ``IntegerField``, except that it fits numbers from
     137-9223372036854775808 to 9223372036854775807
     138
    129139``BooleanField``
    130140~~~~~~~~~~~~~~~~
    131141
Back to Top