Ticket #14286: 14286-Add_BigAutoField.diff

File 14286-Add_BigAutoField.diff, 7.7 KB (added by mmcnickle, 14 years ago)

Adds BigAutoField as a new field type, with documentation.

  • docs/topics/forms/modelforms.txt

     
    4949    Model field                      Form field
    5050    ===============================  ========================================
    5151    ``AutoField``                    Not represented in the form
     52   
     53    ``BigAutoField``                 Not represented in the form
    5254
    5355    ``BigIntegerField``              ``IntegerField`` with ``min_value`` set
    5456                                     to -9223372036854775808 and ``max_value``
  • docs/ref/models/fields.txt

     
    320320primary key field will automatically be added to your model if you don't specify
    321321otherwise. See :ref:`automatic-primary-key-fields`.
    322322
     323``BigAutoField``
     324----------------
     325
     326.. versionadded:: trunk
     327
     328.. class:: BigAutoField(**options)
     329
     330Behaves the same as :class:`AutoField` except it uses a :class:`BigIntegerField`
     331integer as the field. Use this field if you require a larger number of IDs than
     332:class:`AutoField` allows.
     333
     334You may only have one instance of :class:`AutoField` or :class:`BigAutoField`
     335in your model.
     336
    323337``BigIntegerField``
    324338-------------------
    325339
  • django/db/models/fields/__init__.py

     
    487487    def formfield(self, **kwargs):
    488488        return None
    489489
     490class BigAutoField(AutoField):
     491    description = _("Big (8 byte) integer")
     492   
     493    def get_internal_type(self):
     494        return "BigAutoField"
     495
    490496class BooleanField(Field):
    491497    empty_strings_allowed = False
    492498    default_error_messages = {
  • django/db/models/fields/related.py

     
    22from django.db import connection, router, transaction
    33from django.db.backends import util
    44from django.db.models import signals, get_model
    5 from django.db.models.fields import (AutoField, Field, IntegerField,
    6     PositiveIntegerField, PositiveSmallIntegerField, FieldDoesNotExist)
     5from django.db.models.fields import (AutoField, BigAutoField, Field,
     6    BigIntegerField, IntegerField, PositiveIntegerField,
     7    PositiveSmallIntegerField, FieldDoesNotExist)
    78from django.db.models.related import RelatedObject
    89from django.db.models.query import QuerySet
    910from django.db.models.query_utils import QueryWrapper
     
    919920    def db_type(self, connection):
    920921        # The database column type of a ForeignKey is the column type
    921922        # of the field to which it points. An exception is if the ForeignKey
    922         # points to an AutoField/PositiveIntegerField/PositiveSmallIntegerField,
    923         # in which case the column type is simply that of an IntegerField.
     923        # points to an AutoField/BigAutoField/PositiveIntegerField/
     924        # PositiveSmallIntegerField,
     925        # in which case the column type is simply that of an IntegerField
     926        # (or BigIntegerField in the case of BigAutoField).
    924927        # If the database needs similar types for key fields however, the only
    925         # thing we can do is making AutoField an IntegerField.
     928        # thing we can do is to make AutoField an IntegerField
     929        # or BigAutoField a BigIntegerField
    926930        rel_field = self.rel.get_related_field()
     931        if isinstance(rel_field, BigAutoField):
     932            return BigIntegerField().db_type(connection=connection)
    927933        if (isinstance(rel_field, AutoField) or
    928934                (not connection.features.related_fields_match_type and
    929935                isinstance(rel_field, (PositiveIntegerField,
  • django/db/backends/postgresql/creation.py

     
    88    # If a column type is set to None, it won't be included in the output.
    99    data_types = {
    1010        'AutoField':         'serial',
     11        'BigAutoField':      'bigserial',
    1112        'BooleanField':      'boolean',
    1213        'CharField':         'varchar(%(max_length)s)',
    1314        'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
  • django/db/backends/sqlite3/base.py

     
    149149        internal_type = field.get_internal_type()
    150150        if internal_type == 'DecimalField':
    151151            return util.typecast_decimal(field.format_number(value))
    152         elif internal_type and internal_type.endswith('IntegerField') or internal_type == 'AutoField':
     152        elif internal_type and internal_type.endswith('IntegerField') or internal_type.endswith('AutoField'):
    153153            return int(value)
    154154        elif internal_type == 'DateField':
    155155            return util.typecast_date(value)
  • django/db/backends/sqlite3/creation.py

     
    88    # schema inspection is more useful.
    99    data_types = {
    1010        'AutoField':                    'integer',
     11        'BigAutoField':                 'bigint',
    1112        'BooleanField':                 'bool',
    1213        'CharField':                    'varchar(%(max_length)s)',
    1314        'CommaSeparatedIntegerField':   'varchar(%(max_length)s)',
  • django/db/backends/mysql/creation.py

     
    77    # If a column type is set to None, it won't be included in the output.
    88    data_types = {
    99        'AutoField':         'integer AUTO_INCREMENT',
     10        'BigAutoField':      'bigint AUTO_INCREMENT',
    1011        'BooleanField':      'bool',
    1112        'CharField':         'varchar(%(max_length)s)',
    1213        'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
  • django/db/backends/oracle/creation.py

     
    1515
    1616    data_types = {
    1717        'AutoField':                    'NUMBER(11)',
     18        'BigAutoField':                 'NUMBER(19)',
    1819        'BooleanField':                 'NUMBER(1) CHECK (%(qn_column)s IN (0,1))',
    1920        'CharField':                    'NVARCHAR2(%(max_length)s)',
    2021        'CommaSeparatedIntegerField':   'VARCHAR2(%(max_length)s)',
  • django/db/backends/__init__.py

     
    565565        internal_type = field.get_internal_type()
    566566        if internal_type == 'DecimalField':
    567567            return value
    568         elif internal_type and internal_type.endswith('IntegerField') or internal_type == 'AutoField':
     568        elif internal_type and internal_type.endswith('IntegerField') or internal_type.endswith('AutoField'):
    569569            return int(value)
    570570        elif internal_type in ('DateField', 'DateTimeField', 'TimeField'):
    571571            return value
Back to Top