how to model a postal address

Here’s how I model addresses for the US. You could also store a 10 digit zip code (XXXXX-XXXX) if you needed.

You may also consider adding a point field, or a poly field from geodjango depending on what you’re using the addresses for.

from django.contrib.gis.db import models
from django.utils.translation import ugettext as _
from django.contrib.localflavor.us.models import USStateField

class UsLocation(models.Model):
    address_1 = models.CharField(_("address"), max_length=128)
    address_2 = models.CharField(_("address cont'd"), max_length=128, blank=True)

    city = models.CharField(_("city"), max_length=64, default="Zanesville")
    state = USStateField(_("state"), default="OH")
    zip_code = models.CharField(_("zip code"), max_length=5, default="43701")

Leave a Comment

tech