Postal Code model field shows up as State list in Admin

3k Views Asked by At

Not sure, but I think this may be a bug?

Here is my model:

class Property(models.Model):
Name = models.CharField(max_length=40)
Description = models.TextField(default="Description Not Available")
Address = models.CharField(max_length=60, default="Not Available")
Address2 = models.CharField(max_length=60,null=True)
City = models.CharField(max_length=60, null=True)
State = usa_model.USStateField(null=True)
Code = usa_model.USPostalCodeField(null=True)
Phone = usa_model.PhoneNumberField(null=True)

enter image description here

Am I missing something?

-Kerry

1

There are 1 best solutions below

5
On BEST ANSWER

Perhaps you are looking for the US Zip Code Form Field?

The USPostalCodeField uses a list of the states + a few extras:

COFA_STATES = (
    ('FM', 'Federated States of Micronesia'),
    ('MH', 'Marshall Islands'),
    ('PW', 'Palau'),
)

At django.contrib.localflavor.us.us_states

# USStateField
STATE_CHOICES = tuple(sorted(US_STATES + US_TERRITORIES + ARMED_FORCES_STATES, key=lambda obj: obj[1]))

# USPostalCodeField
USPS_CHOICES = tuple(sorted(US_STATES + US_TERRITORIES + ARMED_FORCES_STATES + COFA_STATES, key=lambda obj: obj[1]))