Ticket #8664: 8664-2.diff

File 8664-2.diff, 5.9 KB (added by Matt McClanahan, 16 years ago)

Add db_type method, backends.*.creation references, fix test error

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

     
    731731        defaults.update(kwargs)
    732732        return super(NullBooleanField, self).formfield(**defaults)
    733733
    734 class PhoneNumberField(Field):
    735     def get_internal_type(self):
    736         return "PhoneNumberField"
    737 
    738     def formfield(self, **kwargs):
    739         from django.contrib.localflavor.us.forms import USPhoneNumberField
    740         defaults = {'form_class': USPhoneNumberField}
    741         defaults.update(kwargs)
    742         return super(PhoneNumberField, self).formfield(**defaults)
    743 
    744734class PositiveIntegerField(IntegerField):
    745735    def get_internal_type(self):
    746736        return "PositiveIntegerField"
  • django/db/backends/postgresql/creation.py

     
    2121        'IPAddressField':    'inet',
    2222        'NullBooleanField':  'boolean',
    2323        'OneToOneField':     'integer',
    24         'PhoneNumberField':  'varchar(20)',
    2524        'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
    2625        'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
    2726        'SlugField':         'varchar(%(max_length)s)',
  • django/db/backends/sqlite3/creation.py

     
    2222        'IPAddressField':               'char(15)',
    2323        'NullBooleanField':             'bool',
    2424        'OneToOneField':                'integer',
    25         'PhoneNumberField':             'varchar(20)',
    2625        'PositiveIntegerField':         'integer unsigned',
    2726        'PositiveSmallIntegerField':    'smallint unsigned',
    2827        'SlugField':                    'varchar(%(max_length)s)',
  • django/db/backends/mysql/creation.py

     
    2121        'IPAddressField':    'char(15)',
    2222        'NullBooleanField':  'bool',
    2323        'OneToOneField':     'integer',
    24         'PhoneNumberField':  'varchar(20)',
    2524        'PositiveIntegerField': 'integer UNSIGNED',
    2625        'PositiveSmallIntegerField': 'smallint UNSIGNED',
    2726        'SlugField':         'varchar(%(max_length)s)',
  • django/db/backends/oracle/creation.py

     
    3030        'IPAddressField':               'VARCHAR2(15)',
    3131        'NullBooleanField':             'NUMBER(1) CHECK ((%(qn_column)s IN (0,1)) OR (%(qn_column)s IS NULL))',
    3232        'OneToOneField':                'NUMBER(11)',
    33         'PhoneNumberField':             'VARCHAR2(20)',
    3433        'PositiveIntegerField':         'NUMBER(11) CHECK (%(qn_column)s >= 0)',
    3534        'PositiveSmallIntegerField':    'NUMBER(11) CHECK (%(qn_column)s >= 0)',
    3635        'SlugField':                    'NVARCHAR2(50)',
  • django/contrib/localflavor/us/models.py

     
     1from django.db.models.fields import Field
     2
     3class PhoneNumberField(Field):
     4    def db_type(self):
     5        from django.conf import settings
     6        if settings.DATABASE_ENGINE == 'oracle':
     7            return 'VARCHAR2(20)'
     8        else:
     9            return 'varchar(20)'
     10
     11    def get_internal_type(self):
     12        return "PhoneNumberField"
     13
     14    def formfield(self, **kwargs):
     15        from django.contrib.localflavor.us.forms import USPhoneNumberField
     16        defaults = {'form_class': USPhoneNumberField}
     17        defaults.update(kwargs)
     18        return super(PhoneNumberField, self).formfield(**defaults)
  • tests/modeltests/model_forms/models.py

     
    8282    def __unicode__(self):
    8383        return "%s is %s" % (self.writer, self.age)
    8484
     85from django.contrib.localflavor.us.models import PhoneNumberField
    8586class PhoneNumber(models.Model):
    86     phone = models.PhoneNumberField()
     87    phone = PhoneNumberField()
    8788    description = models.CharField(max_length=20)
    8889
    8990    def __unicode__(self):
  • tests/regressiontests/serializers_regress/models.py

     
    88from django.db import models
    99from django.contrib.contenttypes import generic
    1010from django.contrib.contenttypes.models import ContentType
     11from django.contrib.localflavor.us.models import PhoneNumberField
    1112
    1213# The following classes are for testing basic data
    1314# marshalling, including NULL values.
     
    5253    data = models.NullBooleanField(null=True)
    5354
    5455class PhoneData(models.Model):
    55     data = models.PhoneNumberField(null=True)
     56    data = PhoneNumberField(null=True)
    5657
    5758class PositiveIntegerData(models.Model):
    5859    data = models.PositiveIntegerField(null=True)
     
    188189#     data = models.NullBooleanField(primary_key=True)
    189190
    190191class PhonePKData(models.Model):
    191     data = models.PhoneNumberField(primary_key=True)
     192    data = PhoneNumberField(primary_key=True)
    192193
    193194class PositiveIntegerPKData(models.Model):
    194195    data = models.PositiveIntegerField(primary_key=True)
Back to Top