Skip to content

Instantly share code, notes, and snippets.

@dmenisdev
Last active December 10, 2022 12:08
Show Gist options
  • Save dmenisdev/6dd5fe970ce9f1b89f0310e75749264a to your computer and use it in GitHub Desktop.
Save dmenisdev/6dd5fe970ce9f1b89f0310e75749264a to your computer and use it in GitHub Desktop.
Simple international non-localised shipping address fields [Django ORM]

Objective

Create a minimal simple set of fields to store shipping address for use in non-localised forms that can be used to easliy create shipping address labels.

Reasoning

full_name Can't get more simple than that 😂. Reasons for this can be found at w3.org personal names you'll find some good advice here if you want to go more fancy that just the one field. Field size of 70 comes from UK Government Data Standards Catalogue.

address fields Most international shipping requirements state that a shipping label should have only 2 address lines not exceeding 50 characters each.

city Line on an address label should, in general, not exceeding 50 characters. Which should suffice based on this list of long place names.

Country field For this field I've used a Django specific model field type that contains all the ISO 3166-1 countries. Django package django-countries

Region Optional field. This information is not strictly necessary or could be included in one of the address lines. Purpose is to enter a region name like country area, district, state, province or county.

Address label (form)

[organisation] optional
[full_name]
[street_address_1]
[street_address_2] optional
[city] [postcode]
[region] optional
[country]

References

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_countries.fields import CountryField # https://pypi.org/project/django-countries/
class shipping_address(models.Model):
# addressees full legal name
full_name = models.CharField(max_length=70, blank=True, verbose_name=_('Full name'))
organisation = models.CharField(max_length=50, blank=True, verbose_name=_('Organisation/Company name'))
street_address_1 = models.CharField(max_length=50, blank=True, verbose_name=_('Street address line 1'))
street_address_2 = models.CharField(max_length=50, blank=True, verbosename=_('Street address line 2'))
# postal code, zip code
postcode = models.CharField(max_length=20, blank=True, verbose_name=_('Postal code'))
# city, town, village
city = models.CharField(max_length=50, blank=True)
# country area, district, state, province, county, locality
region = models.CharField(max_length=50, blank=True)
# country (contains all ISO 3166-1 countries codes)
country = CountryField()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment