28 lines
946 B
Python
28 lines
946 B
Python
from django.conf import settings
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from django.db.models.fields import CharField
|
|
from django.contrib.localflavor.us.us_states import STATE_CHOICES
|
|
|
|
class USStateField(CharField):
|
|
|
|
description = _("U.S. state (two uppercase letters)")
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
kwargs['choices'] = STATE_CHOICES
|
|
kwargs['max_length'] = 2
|
|
super(USStateField, self).__init__(*args, **kwargs)
|
|
|
|
class PhoneNumberField(CharField):
|
|
|
|
description = _("Phone number")
|
|
|
|
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)
|