Ticket #10969: localflavor.us.models.usstatefield.3.diff

File localflavor.us.models.usstatefield.3.diff, 1.2 KB (added by Paul McLanahan, 16 years ago)

One more try, this time without appending.

  • django/contrib/localflavor/us/models.py

     
    11from django.conf import settings
    2 from django.db.models.fields import Field
     2from django.db.models.fields import Field, CharField
     3from django.contrib.localflavor.us.us_states import STATE_CHOICES
    34
    4 class USStateField(Field):
    5     def get_internal_type(self):
    6         return "USStateField"
    7        
    8     def db_type(self):
    9         if settings.DATABASE_ENGINE == 'oracle':
    10             return 'CHAR(2)'
    11         else:
    12             return 'varchar(2)'
    13    
    14     def formfield(self, **kwargs):
    15         from django.contrib.localflavor.us.forms import USStateSelect
    16         defaults = {'widget': USStateSelect}
    17         defaults.update(kwargs)
    18         return super(USStateField, self).formfield(**defaults)
     5class USStateField(models.CharField):
     6    def __init__(self, *args, **kwargs):
     7        kwargs['choices'] = STATE_CHOICES
     8        kwargs['max_length'] = 2
     9        super(USStateField, self).__init__(*args, **kwargs)
    1910
    2011class PhoneNumberField(Field):
    2112    def get_internal_type(self):
Back to Top