Login

StateField

Author:
retro486
Posted:
July 22, 2009
Language:
Python
Version:
1.0
Score:
-1 (after 1 ratings)

Based on CountryField.

 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. Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 months ago

Comments

ewalstad (on July 22, 2009):

See also:

django/contrib/localflavor/us/us_states.py

#

Please login first before commenting.