StateField

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from django.utils.translation import ugettext as _
from django.db import models

STATES = (
    ('AK', _('Alaska')),
    ('AL', _('Alabama')),
    ('AR', _('Arkansas')),
    ('AZ', _('Arizona')),
    ('CA', _('California')),
    ('CO', _('Colorado')),
    ('CT', _('Connecticut')),
    ('DE', _('Delaware')),
    ('FL', _('Florida')),
    ('GA', _('Georgia')),
    ('HI', _('Hawaii')),
    ('IA', _('Iowa')),
    ('ID', _('Idaho')),
    ('IL', _('Illinois')),
    ('IN', _('Indiana')),
    ('KS', _('Kansas')),
    ('KY', _('Kentucky')),
    ('LA', _('Louisiana')),
    ('MA', _('Massachusetts')),
    ('MD', _('Maryland')),
    ('ME', _('Maine')),
    ('MI', _('Michigan')),
    ('MN', _('Minnesota')),
    ('MO', _('Missouri')),
    ('MS', _('Mississippi')),
    ('MT', _('Montana')),
    ('NC', _('North Carolina')),
    ('ND', _('North Dakota')),
    ('NE', _('Nebraska')),
    ('NH', _('New Hampshire')),
    ('NJ', _('New Jersey')),
    ('NM', _('New Mexico')),
    ('NV', _('Nevada')),
    ('NY', _('New York')),
    ('OH', _('Ohio')),
    ('OK', _('Oklahoma')),
    ('OR', _('Oregon')),
    ('PA', _('Pennsylvania')),
    ('RI', _('Rhode Island')),
    ('SC', _('South Carolina')),
    ('SD', _('South Dakota')),
    ('TN', _('Tennessee')),
    ('TX', _('Texas')),
    ('UT', _('Utah')),
    ('VT', _('Vermont')),
    ('VA', _('Virginia')),
    ('WA', _('Washington')),
    ('WI', _('Wisconsin')),
    ('WV', _('West Virginia')),
    ('WY', _('Wyoming')),
)

class StateField(models.CharField):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('max_length', 2)
        kwargs.setdefault('choices', STATES)

        super(StateField, self).__init__(*args, **kwargs)

    def get_internal_type(self):
        return "CharField"

More like this

  1. . by jeremydw 3 years, 8 months ago
  2. madslug by catellar 2 years, 8 months ago
  3. watermark by dingdongquan 3 years, 3 months ago
  4. convert youtube url for iframe, js api by ivanff 1 year, 1 month ago
  5. default url routing and shortcut by vicalloy 4 years, 10 months ago

Comments

ewalstad (on July 22, 2009):

See also:

django/contrib/localflavor/us/us_states.py

#

(Forgotten your password?)