Address model

 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
from django.db import models
from django.utils.translation import ugettext_lazy as _

class Address(models.Model):
    TYPES_CHOICES = (
        ('HOME', u('Home')),
        ('WORK', u('Work')),
        ('OTHER', u('Other'))
    )

    type = models.CharField(_('Type'), maxlength=20, choices = TYPES_CHOICES)

    civility = models.CharField(_('Status'), max_length = 20, blank = True)
    firstname = models.CharField(_('Firstname'), max_length = 50, blank = True)
    lastname = models.CharField(_('Lastname'), max_length = 50, blank = True)
    departement = models.CharField(_('Departement'), max_length = 50, blank = True)
    corporation = models.CharField(_('Corporation'), max_length = 100, blank = True)
    building = models.CharField(_('Building'), max_length = 20, blank = True)
    floor = models.CharField(_('Floor'), max_length = 20, blank = True)
    door = models.CharField(_('Door'), max_length = 20, blank = True)
    number = models.CharField(_('Number'), max_length = 30, blank = True)
    street_line1 = models.CharField(_('Address 1'), max_length = 100, blank = True)
    street_line2 = models.CharField(_('Address 2'), max_length = 100, blank = True)
    zipcode = models.CharField(_('ZIP code'), max_length = 5, blank = True)
    city = models.CharField(_('City'), max_length = 100, blank = True)
    state = models.CharField(_('State'), max_length = 100, blank = True)

    # French specifics fields
    cedex = models.CharField(_('CEDEX'), max_length = 100, blank = True)
    
    postal_box = models.CharField(_('Postal box'), max_length = 20, blank = True)
    country = models.CharField(_('Country'), max_length = 100, blank = True)

More like this

  1. MAC address field by diverman 5 years, 1 month ago
  2. Save Geolocation for an Address based model on save() by publicFunction 9 months ago
  3. Tuned IPAddressField with IPv4 & IPv6 support by diverman 5 years, 1 month ago
  4. Models for Postal Addresses by MasonM 5 years, 9 months ago
  5. Validation for full e-mails (e.g. "Joe Hacker <joe@hacker.com>") by akaihola 2 years, 4 months ago

Comments

joey (on February 11, 2009):

Helpful model. There are a few minor errors though:

lines 6,7 and 8 the 'u' should be '_'

line 11 'maxlength' should be 'max_length'

#

matiasherranz (on October 25, 2012):

Nice work!

PEP8 tip: don't use spaces between parameter / keyword equals.

For instance, line 29 should go like this to fit PEP8:

cedex = models.CharField(_('CEDEX'), max_lengt =100, blank=True)

Thanks for sharing!

Matías matiasherranz@gmail.com

#

(Forgotten your password?)