This is standart address model.
Must match US / GB / French address and other...
Specifics locales fields are notice by comments.
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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
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'
#
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
#
Please login first before commenting.