2008-09-02 06:15:35 +08:00
|
|
|
from django.conf import settings
|
2009-12-14 05:56:18 +08:00
|
|
|
from django.db.models.fields import Field, CharField
|
|
|
|
from django.contrib.localflavor.us.us_states import STATE_CHOICES
|
|
|
|
|
|
|
|
class USStateField(CharField):
|
2009-12-13 04:25:41 +08:00
|
|
|
"""U.S. state (two uppercase letters)"""
|
2009-12-14 05:56:18 +08:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
kwargs['choices'] = STATE_CHOICES
|
|
|
|
kwargs['max_length'] = 2
|
|
|
|
super(USStateField, self).__init__(*args, **kwargs)
|
|
|
|
|
2008-09-02 06:15:35 +08:00
|
|
|
class PhoneNumberField(Field):
|
2009-12-13 04:25:41 +08:00
|
|
|
"""Phone number"""
|
2008-09-02 06:15:35 +08:00
|
|
|
def get_internal_type(self):
|
|
|
|
return "PhoneNumberField"
|
|
|
|
|
|
|
|
def db_type(self):
|
|
|
|
if settings.DATABASE_ENGINE == 'oracle':
|
|
|
|
return 'VARCHAR2(20)'
|
|
|
|
else:
|
|
|
|
return 'varchar(20)'
|
|
|
|
|
|
|
|
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)
|
|
|
|
|