Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #12474 - Removing SQL specific bits from USPhoneNumberField. Pa…

…tch from Alex Gaynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12049 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0e883508936fc5d8e499e702a62413440fa66f0b 1 parent d48f530
@jezdez jezdez authored
View
4 django/contrib/localflavor/us/forms.py
@@ -3,7 +3,7 @@
"""
from django.forms import ValidationError
-from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES
+from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES, CharField
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
@@ -20,7 +20,7 @@ def __init__(self, *args, **kwargs):
super(USZipCodeField, self).__init__(r'^\d{5}(?:-\d{4})?$',
max_length=None, min_length=None, *args, **kwargs)
-class USPhoneNumberField(Field):
+class USPhoneNumberField(CharField):
default_error_messages = {
'invalid': u'Phone numbers must be in XXX-XXX-XXXX format.',
}
View
16 django/contrib/localflavor/us/models.py
@@ -1,6 +1,6 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
-from django.db.models.fields import Field, CharField
+from django.db.models.fields import CharField
from django.contrib.localflavor.us.us_states import STATE_CHOICES
class USStateField(CharField):
@@ -12,22 +12,16 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 2
super(USStateField, self).__init__(*args, **kwargs)
-class PhoneNumberField(Field):
+class PhoneNumberField(CharField):
description = _("Phone number")
- def get_internal_type(self):
- return "PhoneNumberField"
-
- def db_type(self, connection):
- if connection.settings_dict['ENGINE'] == 'django.db.backends.oracle':
- return 'VARCHAR2(20)'
- else:
- return 'varchar(20)'
+ def __init__(self, *args, **kwargs):
+ kwargs['max_length'] = 20
+ super(PhoneNumberField, self).__init__(*args, **kwargs)
def formfield(self, **kwargs):
from django.contrib.localflavor.us.forms import USPhoneNumberField
defaults = {'form_class': USPhoneNumberField}
defaults.update(kwargs)
return super(PhoneNumberField, self).formfield(**defaults)
-
Please sign in to comment.
Something went wrong with that request. Please try again.