Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Provides a country field for Django models.

Project Description

A Django application which provides country choices for use with forms, and a country field for models.

To use the flags, use the django.contrib.staticfiles app added in Django 1.3 (or django-staticfiles application for previous Django versions).

CountryField

A country field for Django models that provides all ISO 3166-1 countries as choices.

CountryField is based on Django’s CharField, providing choices corresponding to the official ISO 3166-1 list of countries (with a default max_length of 2).

Consider the following model using a CountryField:

from django.db import models
from django_countries import CountryField

class Person(models.Model):
    name = models.CharField(max_length=100)
    country = CountryField()

Any Person instance will have a country attribute that you can use to get details of the person’s country:

>>> person = Person(name='Chris', country='NZ')
>>> person.country
Country(code='NZ')
>>> person.country.name
u'New Zealand'
>>> person.country.flag
u'/static/flags/nz.gif'

This object (person.country in the example) is a Country instance, which is described below.

The Country object

An object used to represent a country, instanciated with a two character country code.

It can be compared to other objects as if it was a string containing the country code, and it’s __unicode__ method returns the country code.

name
Contains the full country name.
flag
Contains a URL to the flag. 'flags/[lowercasecountrycode].gif' is appended to the STATIC_URL setting, or if that isn’t set, the MEDIA_URL setting.

Country Choices

The django_countries.countries module contains some constants which can be used to generate choices lists for a Django Select form field.

COUNTRIES
A tuple of two part tuples, each consisting of a country code and the corresponding nicely titled (and translatable) country name.
COUNTRIES_PLUS
A tuple, similar to COUNTRIES, but also includes duplicates for countries that contain a comma (i.e. the non-comma’d version).
OFFICIAL_COUNTRIES
A dictionary where each key is a country code and each value is the corresponding official capitalised ISO 3166-1 English country name.
Release History

Release History

History Node

5.0

History Node

4.6.2

History Node

4.6.1

History Node

4.6

History Node

4.5

History Node

4.4

History Node

4.3

History Node

4.2

History Node

4.1

History Node

4.0

History Node

3.4.1

History Node

3.4

History Node

3.3

History Node

3.2

History Node

3.1.1

History Node

3.1

History Node

3.0.2

History Node

3.0.1

History Node

3.0

History Node

2.1.2

History Node

2.1.1

History Node

2.1

History Node

2.0

This version
History Node

1.5

History Node

1.4

History Node

1.3

History Node

1.2

History Node

1.1.2

History Node

1.1.1

History Node

1.1

History Node

1.0.7

History Node

1.0.6.1

History Node

1.0.6

History Node

1.0.5

History Node

1.0.4

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-countries-1.5.tar.gz (191.8 kB) Copy SHA256 Checksum SHA256 Source Dec 28, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting